73 lines
1.2 KiB
Nim
73 lines
1.2 KiB
Nim
import std/[
|
|
mimetypes,
|
|
os,
|
|
strformat,
|
|
]
|
|
import fp/[
|
|
map,
|
|
]
|
|
import ./errors
|
|
|
|
const PORT_DEFAULT* = 1337
|
|
const HTML_ROOT* = "../js"
|
|
const DIST_ROOT* = HTML_ROOT.joinPath("dist")
|
|
|
|
type
|
|
orgPath* = string
|
|
orgId* = string
|
|
# OrgEnv* = ref object
|
|
# paths*: seq[tuple[
|
|
# path: orgPath,
|
|
# id: orgId,
|
|
# ]]
|
|
|
|
type
|
|
debugLevel* = enum
|
|
log
|
|
|
|
type
|
|
Env* = ref object
|
|
port*: int
|
|
mimeTypes*: MimeDb
|
|
debugLevel*: debugLevel
|
|
|
|
htmlRoot*: string
|
|
distRoot*: string
|
|
|
|
orgEnv*: Map[orgId, orgPath]
|
|
|
|
proc debugLog*(env: Env, content: string): void =
|
|
case env.debugLevel:
|
|
of log: echo(content)
|
|
|
|
proc logErr*(env: Env, err: orgEnvErr, t1: string): void {.inline.} =
|
|
debugLog(env, stringify(err, t1))
|
|
|
|
proc initEnv*(): Env =
|
|
Env(
|
|
port: PORT_DEFAULT,
|
|
mimeTypes: newMimetypes(),
|
|
debugLevel: log,
|
|
|
|
htmlRoot: HTML_ROOT,
|
|
distRoot: DIST_ROOT,
|
|
|
|
orgEnv: @[
|
|
("Main", "~/Documents/Org/Main/".expandTilde()),
|
|
("Work", "~/Documents/Org/Work/".expandTilde()),
|
|
].asMap()
|
|
)
|
|
|
|
proc `$`*(x: Env): string =
|
|
&"""Env(
|
|
port: {x.port},
|
|
debugLevel: {x.debugLevel},
|
|
htmlRoot: {x.htmlRoot},
|
|
distRoot: {x.distRoot},
|
|
orgEnv: {x.orgEnv},
|
|
)
|
|
"""
|
|
|
|
when isMainModule:
|
|
echo initEnv()
|