-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ml
56 lines (45 loc) · 1.31 KB
/
config.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
46
47
48
49
50
51
52
53
54
55
56
open Mirage
(* If the Unix `MODE` is set, the choice of configuration changes:
MODE=crunch (or nothing): use static filesystem via crunch
MODE=fat: use FAT and block device (run ./make-fat-images.sh)
*)
let mode =
try match String.lowercase (Unix.getenv "FS") with
| "fat" -> `Fat
| _ -> `Crunch
with Not_found ->
`Crunch
let fat_ro dir =
kv_ro_of_fs (fat_of_files ~dir ())
let fs = match mode with
| `Fat -> fat_ro "./htdocs"
| `Crunch -> crunch "./htdocs"
let net =
try match Sys.getenv "NET" with
| "direct" -> `Direct
| "socket" -> `Socket
| _ -> `Direct
with Not_found -> `Direct
let dhcp =
try match Sys.getenv "DHCP" with
| "" -> false
| _ -> true
with Not_found -> false
let stack console =
match net, dhcp with
| `Direct, true -> direct_stackv4_with_dhcp console tap0
| `Direct, false -> direct_stackv4_with_default_ipv4 console tap0
| `Socket, _ -> socket_stackv4 console [Ipaddr.V4.any]
let server =
conduit_direct (stack default_console)
let http_srv =
let mode = `TCP (`Port 80) in
http_server mode server
let main =
foreign "Dispatch.Main" (console @-> kv_ro @-> http @-> job)
let () =
add_to_ocamlfind_libraries ["re.str"];
add_to_opam_packages ["re"];
register "www" [
main $ default_console $ fs $ http_srv
]