-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.js
45 lines (39 loc) · 993 Bytes
/
response.js
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
/**
* @fileoverview JSGI Response Helpers
*/
export('redirect', 'respond', 'error', 'notfound', 'badrequest');
function redirect(path) {
return {
status: 302,
headers: {'Location': path},
body: []
};
};
function respond(body) {
return {
status: 200,
headers: {'Content-Type': 'text/html'},
body: [body]
};
};
function error() {
return {
status: 200, // 500,
headers: {'Content-Type': 'text/html'},
body: ['<h1>500 Internal Server Error</h1> <quote>You know what they say about me? I suck!</quote>']
}
};
function notfound() {
return {
status: 200, // 404,
headers: {'Content-Type': 'text/html'},
body: ["<h1>404 Not Found</h1> <quote>If we don't got it, you don't want it!</quote>"]
};
};
function badrequest() {
return {
status: 200, // 400 bad request
headers: {'content-Type': 'text/html'},
body: ["<h1>400 Bad request</h1> <quote>Die in a fire!</quote>"]
};
};