You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
850 B
31 lines
850 B
var util = require('util'),
|
|
flatiron = require('../lib/flatiron'),
|
|
app = flatiron.app;
|
|
|
|
app.use(flatiron.plugins.http);
|
|
|
|
app.router.get('/', function () {
|
|
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
this.res.end('Hello world!\n');
|
|
});
|
|
|
|
app.router.post('/', function () {
|
|
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
this.res.write('Hey, you posted some cool data!\n');
|
|
this.res.end(util.inspect(this.req.body, true, 2, true) + '\n');
|
|
});
|
|
|
|
app.router.get('/sandwich/:type', function (type) {
|
|
if (~['bacon', 'burger'].indexOf(type)) {
|
|
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
this.res.end('Serving ' + type + ' sandwich!\n');
|
|
}
|
|
else {
|
|
this.res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
this.res.end('No such sandwich, sorry!\n');
|
|
}
|
|
});
|
|
|
|
app.start(8080);
|
|
|