Fixup settings handling slightly

This commit is contained in:
Quad 2022-04-11 08:38:03 +02:00
parent 0a24eaadfa
commit e51ba4d34d
3 changed files with 20 additions and 7 deletions

View File

@ -1,15 +1,15 @@
import env
import prologue
import templating
import env
proc getIndex*(ctx: Context) {.async.} =
resp renderTemplate(templateName="index.nwt")
proc runWebsite() =
let settings = newSettings(
debug = boolEnvOrDefault("DEBUG", false)
proc runWebsite(settings: Table) =
let prologueSettings = newSettings(
debug = settings["debug"]
)
let website = newApp(settings = settings)
let website = newApp(settings = prologueSettings)
website.get("/", getIndex)

View File

@ -8,4 +8,10 @@ proc boolEnvOrDefault(envName: string, default: bool): bool =
else:
return default
export boolEnvOrDefault
proc strEnvOrDefault(envName: string, default: string): string =
if existsEnv(envName):
return getEnv(envName)
else:
return default
export boolEnvOrDefault, strEnvOrDefault

View File

@ -1,8 +1,15 @@
when isMainModule:
import tables
import modules/blog
import modules/env
let settings = {
"debug": boolEnvOrDefault("DEBUG", false),
"logging": boolEnvOrDefault("NIMBLOG_LOG", true)
}.toTable()
try:
echo "Starting website"
runWebsite()
runWebsite(settings)
except:
echo "Could not run website"