Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* index.js: Test helpers for director.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var http = require('http');
10
11
exports.createServer = function (router) {
12
return http.createServer(function (req, res) {
13
router.dispatch(req, res, function (err) {
14
if (err) {
15
res.writeHead(404);
16
res.end();
17
}
18
});
19
});
20
};
21
22
exports.handlers = {
23
respondWithId: function (id) {
24
this.res.writeHead(200, { 'Content-Type': 'text/plain' })
25
this.res.end('hello from (' + id + ')');
26
},
27
respondWithData: function () {
28
this.res.writeHead(200, { 'Content-Type': 'application/json' })
29
this.res.end(JSON.stringify(this.data));
30
},
31
streamBody: function () {
32
var body = '',
33
res = this.res;
34
35
this.req.on('data', function (chunk) {
36
body += chunk;
37
});
38
39
this.req.on('end', function () {
40
res.writeHead(200, { 'Content-Type': 'application/json' });
41
res.end(body);
42
});
43
}
44
};
45
46
exports.macros = require('./macros');
47