forked from planety/prologue-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.nim
32 lines (24 loc) · 1.04 KB
/
app.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
import prologue
import prologue/middlewares/cors
# Pong handler to check if example is running
proc pong(ctx: Context) {.async.} =
resp "pong"
# Test handler that contains 'important' data
proc exampleHandler(ctx: Context) {.async.} =
ctx.response.addHeader("My-Custom-Header", "1234")
resp jsonResponse(%*"""
{
"some key": "some important data
}
""", headers = ctx.response.headers)
# Create default settings
let settings = newSettings()
# Create instance
var app = newApp(settings = settings)
# Create routes
app.addRoute("/ping", pong, middlewares = @[CorsMiddleware(allowOrigins = @["*"])])
app.addRoute("/test-origin", exampleHandler, middlewares = @[CorsMiddleware(allowOrigins = @["*"])])
app.addRoute("/test-expose-content-length", exampleHandler, middlewares = @[CorsMiddleware(allowOrigins = @["*"], exposeHeaders = @["Content-Length"])])
app.addRoute("/test-put-method", exampleHandler, HttpPut, middlewares = @[CorsMiddleware(allowOrigins = @["*"], allowMethods = @["put"])])
# Run instance
app.run()