Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
var util = require('util'),
2
flatiron = require('../lib/flatiron'),
3
app = flatiron.app;
4
5
app.use(flatiron.plugins.http);
6
7
app.router.get('/', function () {
8
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
9
this.res.end('Hello world!\n');
10
});
11
12
app.router.post('/', function () {
13
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
14
this.res.write('Hey, you posted some cool data!\n');
15
this.res.end(util.inspect(this.req.body, true, 2, true) + '\n');
16
});
17
18
app.router.get('/sandwich/:type', function (type) {
19
if (~['bacon', 'burger'].indexOf(type)) {
20
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
21
this.res.end('Serving ' + type + ' sandwich!\n');
22
}
23
else {
24
this.res.writeHead(404, { 'Content-Type': 'text/plain' });
25
this.res.end('No such sandwich, sorry!\n');
26
}
27
});
28
29
app.start(8080);
30
31
32