-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.nim
63 lines (47 loc) · 1.41 KB
/
api.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import prologue
import prologue/middlewares/signedcookiesession
import prologue/middlewares/staticfile
import psutil
import psutil/common
import std/json
import params
import std/logging
import std/strformat
import std/marshal
import std/asyncdispatch
import std/osproc
var consoleLog = newConsoleLogger()
var fileLog = newFileLogger("log_errors.log", levelThreshold=lvlError)
var rollingLog = newRollingFileLogger("log_rolling.log")
addHandler(consoleLog)
addHandler(fileLog)
addHandler(rollingLog)
var oSettings = newSettings(
appName = "capp_system_info_server",
debug = true,
port = Port(SERVER_PORT),
address = SERVER_HOST
)
info(&"Listen to: {SERVER_HOST}:{SERVER_PORT} Secret: {params.SECRET_KEY}\n")
proc authWithSecretKey*(sKey: string): HandlerAsync =
var sLocalKey = sKey
# info(&"[!] authWithSecretKey - {sKey} \n")
result = proc(ctx: Context) {.async.} =
var sSecretKey = ctx.getQueryParams("key", "")
# info(&"[!] {sSecretKey} {sKey} \n")
if sSecretKey != sLocalKey:
return
await switch(ctx)
if (oSettings != nil):
var app = newApp(oSettings)
app.use(
authWithSecretKey(params.SECRET_KEY),
staticFileMiddleware("public"),
sessionMiddleware(oSettings, path = "/")
)
include pages
include api_shell
include api_current
include api_history
include api_servers
app.run()