Source file site_prefix.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Dream = Dream__pure.Inmost
let rec match_site_prefix prefix path =
match prefix, path with
| prefix_crumb::prefix, path_crumb::path ->
if path_crumb = prefix_crumb then
match_site_prefix prefix path
else
None
| [], path ->
Some path
| _ ->
None
let chop_site_prefix prefix =
let prefix =
prefix
|> Dream__pure.Formats.from_target_path
|> Dream__pure.Formats.drop_trailing_slash
in
let prefix_reversed = List.rev prefix in
fun next_handler request ->
match match_site_prefix prefix (Dream.path request) with
| None ->
Dream.empty `Bad_Gateway
| Some path ->
request
|> Dream.with_prefix prefix_reversed
|> Dream.with_path path
|> next_handler