This repository has been archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.coffee
167 lines (151 loc) · 3.02 KB
/
action.coffee
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
module.exports.actionEcho = (ANY) ->
ANY '/echo', (
endJSON
method
req
urlWithoutQuerystring
query
body
userAgent
ip
isGzipEnabled
matchCurrentUrl
basicAuthCredentials
session
token
) ->
endJSON
method: method
url: req.url
urlWithoutQuerystring: urlWithoutQuerystring
query: query
body: body
userAgent: userAgent
ip: ip
isGzipEnabled: isGzipEnabled()
match: matchCurrentUrl('/:part')
alsoMatch: matchCurrentUrl('/echo')
noMatch: matchCurrentUrl('/echo/:id')
basicAuthCredentials: basicAuthCredentials
session: session
token: token
module.exports.actionError = (GET) ->
GET '/error', (
) ->
throw new Error 'TESTING ERRORS: this is supposed to get thrown and logged'
module.exports.actionMethod = (
GET
PUT
POST
DELETE
PATCH
sequenz
) ->
url = '/method'
sequenz(
GET url, (end) -> end 'get'
POST url, (end) -> end 'post'
PUT url, (end) -> end 'put'
PATCH url, (end) -> end 'patch'
DELETE url, (end) -> end 'delete'
)
module.exports.actionAny = (
ANY
) ->
ANY '/any', (
method
end
) ->
end "method is #{method}"
module.exports.actionRedirect = (GET) ->
GET '/redirect', (
redirect
) ->
console.log 'REDIRECTING'
redirect '/redirect-target'
module.exports.actionRedirectTarget = (GET) ->
GET '/redirect-target', (
endText
) ->
endText 'you made it'
module.exports.actionText = (GET) ->
GET '/text', (
endText
) ->
endText 'Hello World'
module.exports.actionJson = (GET) ->
GET '/json', (
endUnprocessableJSON
) ->
endUnprocessableJSON {a: 1}
module.exports.actionXml = (GET) ->
GET '/xml', (
end429XML
) ->
end429XML '<test></test>'
module.exports.actionKup = (GET) ->
GET '/kup', (
layout
k
endKup
pushMeta
$meta
) ->
pushMeta
name: "robots"
content: "index,follow"
pushMeta
name: "keywords"
content: "test"
layout ->
k.span 'content'
endKup()
module.exports.actionReact = (GET) ->
GET '/react', (
ComponentContent
endReact
react
) ->
endReact react.createElement ComponentContent
module.exports.actionReactKup = (GET) ->
GET '/react-kup', (
ComponentContent
end404ReactWithLayout
layout
) ->
end404ReactWithLayout layout, ComponentContent
module.exports.actionSessionGet = (GET) ->
GET '/session', (
session
endJSON
) ->
endJSON session
module.exports.actionSessionSet = (PATCH) ->
PATCH '/session', (
session
body
endJSON
_
) ->
_.extend session, body
endJSON session
module.exports.actionSessionDelete = (DELETE) ->
DELETE '/session', (
session
end
) ->
session.destroy ->
end()
module.exports.actionTokenCreate = (POST) ->
POST '/token', (
newJwt
body
endJSON
) ->
endJSON {token: newJwt(body)}
module.exports.actionTokenRead = (GET) ->
GET '/token', (
token
endJSON
) ->
endJSON token