-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.js
More file actions
37 lines (30 loc) · 753 Bytes
/
response.js
File metadata and controls
37 lines (30 loc) · 753 Bytes
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
var Helpers = require('./helpers')
module.exports = Response
function Response(respond) {
this.body = {}
this.header = {
'Content-type': 'application/json'
}
this.code = 200
this._respond = respond
}
Response.prototype.end = function() {
var bodyStr = (typeof this.body === 'object') ? JSON.stringify(this.body) : this.body
this._respond(this.code, this.header, bodyStr)
}
Response.prototype.status = function(code) {
this.code = code
return this
}
Response.prototype.send = function(body) {
this.body = body
this.end()
}
Response.prototype.set = function(header, value) {
if(header && typeof header === 'object') {
Helpers.merge(this.header, header)
} else {
this.header[header] = value
}
return this
}