forked from HapticX/happyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestc6.nim
63 lines (49 loc) · 1.1 KB
/
testc6.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
../src/happyx,
macros
# regCORS:
# credentials: true
# origins: "*" # "https://www.google.com" # You can send request from this address
# methods: ["GET", "POST", "PUT"]
# headers: "*"
regCORS:
credentials: true
origins: "*"
methods: "*"
headers: "*"
decorator HelloWorld:
# In this scope:
# httpMethods: seq[string]
# routePath: string
# statementList: NimNode
# arguments: seq[NimNode]
statementList.insert(0,
newCall("echo", )
)
for i in arguments:
statementList[0].add(i)
statementList[0].add(newLit", ")
if statementList[0].len > 1:
statementList[0].del(statementList[0].len-1)
mount Test:
get "/":
echo 1
get "/test":
echo 1
serve("127.0.0.1", 5000):
"/":
return "Hello, world!"
@HelloWorld(1, 2, 3, req)
mount "/test" -> Test
@HelloWorld(1, 2, 3, req)
"/test-deco":
return "Hello, world!"
@AuthBasic # username and password will in your code.
get "/user/{id}":
echo username
echo password
return {"response": {
"id": id,
"username": username,
"password": password
}}