forked from planety/prologue-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.nim
51 lines (38 loc) · 1.61 KB
/
views.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
import prologue
import tables, logging
proc articles*(ctx: Context) {.async.} =
resp $ctx.getPathParams("num", 1)
proc hello*(ctx: Context) {.async.} =
# await sleepAsync(3000)
resp "<h1>Hello, Prologue!</h1>"
if true:
raise newException(ValueError, "can't be reached")
proc index*(ctx: Context) {.async.} =
await ctx.staticFileResponse("index.html", "static")
proc helloName*(ctx: Context) {.async.} =
logging.debug ctx.getPathParams("name")
resp "<h1>Hello, " & ctx.getPathParams("name", "World") & "</h1>"
proc home*(ctx: Context) {.async.} =
logging.debug urlFor(ctx, "index")
logging.debug urlFor(ctx, "helloname", {"name": "flywind"}, {"age": "20"})
logging.debug ctx.request.queryParams.getOrDefault("name", "")
resp redirect(urlFor(ctx, "helloname", {"name": "flywind"}, {"age": "20", "hobby": "Nim"}), Http302)
proc testRedirect*(ctx: Context) {.async.} =
resp redirect("/hello", Http302)
proc login*(ctx: Context) {.async.} =
resp loginPage()
proc do_login*(ctx: Context) {.async.} =
logging.debug "-----------------------------------------------------"
logging.debug ctx.request.postParams
resp redirect("/hello/Nim")
proc multiPart*(ctx: Context) {.async.} =
resp multiPartPage()
proc do_multiPart*(ctx: Context) {.async.} =
logging.debug ctx.request.formParams["username"].body
logging.debug ctx.request.formParams["password"].body
resp redirect("/login")
proc upload*(ctx: Context) {.async.} =
await ctx.staticFileResponse("upload.html", "static")
proc do_upload*(ctx: Context) {.async.} =
logging.debug ctx.request.formParams
resp ctx.request.formParams["file"].body