Skip to content

Instantly share code, notes, and snippets.

@ephekt
Created October 12, 2012 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ephekt/3882096 to your computer and use it in GitHub Desktop.
Save ephekt/3882096 to your computer and use it in GitHub Desktop.
nodejs+director
var http = require('http'),
director = require('director');
var router = new director.http.Router({
'/add_log': {
post: function () {
console.log(this.req.body);
this.res.writeHead(200, { 'Content-Type': 'application/json' });
this.res.end(JSON.stringify({status:200}));
}
}
});
var server = http.createServer(function (req, res) {
console.log(req.method + ": " + req.url);
// req.chunks = [];
// req.on('data', function (chunk) {
// req.chunks.push(chunk.toString());
// });
router.dispatch(req, res, function (err) {
if (err) {
console.log(err);
res.writeHead(err.status, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(err));
}
});
});
server.listen('9090','127.0.0.1');
console.log('Server running at http://127.0.0.1:9090/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment