jb/src/app.ml

63 lines
1.4 KiB
OCaml

module App_id = struct
let qualifier = "org"
let organization = "jb"
let application = "jb"
end
module Project_dirs = Directories.Project_dirs (App_id)
let data_dir =
match Project_dirs.data_dir with
| None -> failwith "can't compute data directory"
| Some data_dir -> data_dir
let config_dir =
match Project_dirs.config_dir with
| None -> failwith "can't compute configuration directory"
| Some config_dir -> config_dir
let config =
let filename = Filename.concat config_dir "config.scfg" in
if not @@ Sys.file_exists filename then []
else begin
Dream.log "config file: %s" filename;
match Scfg.Parse.from_file filename with
| Error e -> failwith e
| Ok config -> config
end
open Scfg.Query
let port =
get_dir "port" config
|> Option.map (get_param_pos_int_exn 0)
|> Option.value ~default:8000
let () = Dream.log "port: %d" port
let hostname =
get_dir "hostname" config
|> Option.map (get_param_exn 0)
|> Option.value ~default:(Format.sprintf "localhost:%d" port)
let () = Dream.log "hostname: %s" hostname
let log =
get_dir "log" config
|> Option.map (get_param_bool_exn 0)
|> Option.value ~default:true
let () = Dream.log "log: %b" log
let about =
get_dir "about" config
|> Option.map (get_param_exn 0)
|> Option.value ~default:"JB"
let path_to_images =
match get_dir "path_to_images" config with
| None -> failwith "missing path_to_images in configuration"
| Some dir -> get_param_exn 0 dir