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
45
module Formats = Dream_pure.Formats
module Message = Dream_pure.Message
module Stream = Dream_pure.Stream
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 with_site_prefix prefix =
let prefix =
prefix
|> Formats.from_path
|> Formats.drop_trailing_slash
in
fun next_handler request ->
match match_site_prefix prefix (Router.path request) with
| None ->
Message.response ~status:`Bad_Gateway Stream.empty Stream.null
|> Lwt.return
| Some path ->
Router.set_prefix request (List.rev prefix);
Router.set_path request path;
next_handler request