Skip to content

Instantly share code, notes, and snippets.

@xavi-
Created January 24, 2012 07:31
Show Gist options
  • Save xavi-/1668685 to your computer and use it in GitHub Desktop.
Save xavi-/1668685 to your computer and use it in GitHub Desktop.
Beeline in action
var http = require("http");
var bee = require("beeline");
var route = bee.route({
"`preprocess`": [
(function() {
function sendHtml(data) {
this.writeHead(200, { "Content-Length": data.length,
"Content-Type": "text/html; charset=utf-8" });
this.end(data);
}
function sendJson(json) {
var data = JSON.stringify(json);
this.writeHead(200, { "Content-Length": data.length,
"Content-Type": "application/json; charset=utf-8" });
this.end(data);
}
return function(req, res) {
res.html = sendHtml;
res.json = sendJson;
};
})()
],
"/ /index.html": function(req, res) {
res.html("<b>hello</b>")
},
"/json-service": function(req, res) {
res.json({ send: "json" });
}
});
var server = http.createServer(route);
server.listen(8007);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment