api: Use the standard config pattern for KNOWN_ORIGINS.

This commit is contained in:
Jonathan Bernard 2021-07-05 11:35:35 -05:00
parent 2fd45ac35c
commit a0f9670688

View File

@ -34,19 +34,15 @@ proc loadConfig*(args: Table[string, docopt.Value] = initTable[string, docopt.Va
warn "Cannot read configuration file \"" & filePath & "\":\n\t" &
getCurrentExceptionMsg()
let knownOriginsArray =
if json.hasKey("knownOrigins"): json["knownOrigins"]
else: newJArray()
let cfg = CombinedConfig(docopt: args, json: json)
result = PMApiConfig(
authSecret: cfg.getVal("auth-secret"),
dbConnString: cfg.getVal("db-conn-string"),
debug: "true".startsWith(cfg.getVal("debug", "false").toLower()),
port: parseInt(cfg.getVal("port", "8080")),
port: parseInt(cfg.getVal("port", "8100")),
pwdCost: cast[int8](parseInt(cfg.getVal("pwd-cost", "11"))),
knownOrigins: toSeq(knownOriginsArray).mapIt(it.getStr))
knownOrigins: cfg.getVal("known-origins")[1..^2].split(',').mapIt(it[1..^2]))
proc initContext(args: Table[string, docopt.Value]): PMApiContext =