diff --git a/src/app.ml b/src/app.ml index 62f4996..d556864 100644 --- a/src/app.ml +++ b/src/app.ml @@ -37,11 +37,23 @@ let open_registration = | Error e -> failwith e | Ok "true" -> true | Ok "false" -> false - | Ok unknown -> - failwith - @@ Format.sprintf - "invalid value for `open_registration` in configuration file, \ - expected `true` or `false` but got `%s`" - unknown ) + | Ok _unknown -> + failwith "invalid `open_registration` value in configuration file" ) -let () = Dream.log "open_registration: %s" (Bool.to_string open_registration) +let () = Dream.log "open_registration: %b" open_registration + +let port = + match Scfg.Query.get_dir "port" config with + | None -> 8080 + | Some open_registration -> ( + match Scfg.Query.get_param 0 open_registration with + | Error e -> failwith e + | Ok n -> ( + try + let n = int_of_string n in + if n < 0 then raise (Invalid_argument "negative port number"); + n + with Invalid_argument _msg -> + failwith "invalid `port` value in configuration file" ) ) + +let () = Dream.log "port: %d" port diff --git a/src/permap.ml b/src/permap.ml index 4d07d63..46def5e 100644 --- a/src/permap.ml +++ b/src/permap.ml @@ -246,7 +246,7 @@ let routes = [ get_ "/:thread_id" thread_get; post "/:thread_id" reply_post ] let () = - Dream.run ~port:3696 @@ Dream.logger @@ Dream.cookie_sessions + Dream.run ~port:App.port @@ Dream.logger @@ Dream.cookie_sessions (* this should replace memory/cookie sessions but it doesn't work :-( @@ Dream.sql_pool Db.db_uri @@ Dream.sql_sessions