-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathfaq.md
More file actions
83 lines (58 loc) · 1.9 KB
/
faq.md
File metadata and controls
83 lines (58 loc) · 1.9 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# FAQ
## Threads
`Prologue` supports two HTTP server: `httpbeast` and `asynchttpserver`. If you are in Linux or MacOS, use `--threads:on` to enable the multi-threads HTTP server. If you are in windows, `threads` should not be used. You can use `-d:usestd` to switch to `asynchttpserver` in Linux or MacOS.
## Benchmarking and debug
If you want to benchmark `prologue` or release your programs, make sure to set `settings.debug` = false.
```nim
let
# debug attributes must be false
env = loadPrologueEnv(".env")
settings = newSettings(appName = env.getOrDefault("appName", "Prologue"),
debug = false,
port = Port(env.getOrDefault("port", 8080)),
secretKey = env.getOrDefault("secretKey", "")
)
```
or in `.env` file, set `debug = false`.
```nim
# Don't commit this to source control.
# Eg. Make sure ".env" in your ".gitignore" file.
debug=false # change this
port=8080
appName=HelloWorld
staticDir=/static
secretKey=Pr435ol67ogue
```
## Disable logging
There are two ways to disable logging messages:
- set `settings.debug` = false
- set a startup event
```nim
proc setLoggingLevel() =
addHandler(newConsoleLogger())
logging.setLogFilter(lvlInfo)
let
event = initEvent(setLoggingLevel)
var
app = newApp(settings = settings, startup = @[event])
```
## Avoid using a function name which is same to the module name.
`src/index.nim`
```nim
proc index(ctx: Context) {.async.} =
...
```
## Use the full path of JS, CSS files.
For instance in your HTML file use `templates/some.js` instead of `some.js`.
## Run in async mode
The server can run in async mode, this is useful to perform other tasks beside
accepting connections.
```nim
import prologue
proc handler(ctx: Context) {.async.} =
resp "Hello world"
let settings = newSettings(port = Port(8000))
let app = newApp(settings)
app.all("/*$", handler)
waitFor app.runAsync()
```