Implement org file server
This commit is contained in:
@@ -1,24 +1,72 @@
|
||||
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 Env* = ref object
|
||||
port*: int
|
||||
mimeTypes*: MimeDb
|
||||
htmlRoot*: string
|
||||
distRoot*: string
|
||||
type
|
||||
orgPath* = string
|
||||
orgId* = string
|
||||
# OrgEnv* = ref object
|
||||
# paths*: seq[tuple[
|
||||
# path: orgPath,
|
||||
# id: orgId,
|
||||
# ]]
|
||||
|
||||
proc initEnv*(): auto =
|
||||
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()
|
||||
)
|
||||
|
||||
echo newMimetypes().getMimetype("txt")
|
||||
proc `$`*(x: Env): string =
|
||||
&"""Env(
|
||||
port: {x.port},
|
||||
debugLevel: {x.debugLevel},
|
||||
htmlRoot: {x.htmlRoot},
|
||||
distRoot: {x.distRoot},
|
||||
orgEnv: {x.orgEnv},
|
||||
)
|
||||
"""
|
||||
|
||||
when isMainModule:
|
||||
echo initEnv()
|
||||
|
||||
Reference in New Issue
Block a user