[OCaml] Mobile-friendly clone of cgit.
1
(** Server startup.
2
3
Loads configuration, then hands the resulting routes to Dream. Startup fails
4
loudly rather than falling back to defaults, so a typo in a config file is
5
noticed immediately instead of silently changing which repositories are
6
served. The one exception is an explicit [git_project_root] on the command
7
line, which is enough on its own to run without any config file. *)
8
9
let run_with_config config =
10
Dream.run ~port:config.Config.port ~interface:config.Config.host
11
@@ Dream.logger
12
@@ Dream.router (Handlers.routes config)
13
14
let run ?git_project_root () =
15
let config =
16
match Config.load () with
17
| Ok config -> config
18
| Error error ->
19
if Option.is_some git_project_root then Config.default
20
else failwith (Config.show_load_error error)
21
in
22
let config =
23
match git_project_root with
24
| Some path -> { config with git_project_root = path }
25
| None -> config
26
in
27
run_with_config config
28