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 prologue
import templating import templating
import env
proc getIndex*(ctx: Context) {.async.} = proc getIndex*(ctx: Context) {.async.} =
resp renderTemplate(templateName="index.nwt") resp renderTemplate(templateName="index.nwt")
proc runWebsite() = proc runWebsite(settings: Table) =
let settings = newSettings( let prologueSettings = newSettings(
debug = boolEnvOrDefault("DEBUG", false) debug = settings["debug"]
) )
let website = newApp(settings = settings) let website = newApp(settings = prologueSettings)
website.get("/", getIndex) website.get("/", getIndex)

View File

@ -8,4 +8,10 @@ proc boolEnvOrDefault(envName: string, default: bool): bool =
else: else:
return default 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: when isMainModule:
import tables
import modules/blog import modules/blog
import modules/env
let settings = {
"debug": boolEnvOrDefault("DEBUG", false),
"logging": boolEnvOrDefault("NIMBLOG_LOG", true)
}.toTable()
try: try:
echo "Starting website" echo "Starting website"
runWebsite() runWebsite(settings)
except: except:
echo "Could not run website" echo "Could not run website"