$ npm install content-types
handle multiple content types
var http = create("http")
, contentTypes = require("routil-contentTypes")
http.createServer(function () {
contentTypes(req, {
"text/html": returnHtml
, "application/javascript": returnJson
})(req, res)
}).listen(8080)
function returnHtml(req, res) {
res.end("<ul><li>foo</li><li>bar</li></ul>")
}
function returnJson(req, res) {
res.end(JSON.stringify(["foo", "bar"]))
}
npm install content-types
npm test
© 2010 - cnpmjs.org x YWFE | Home | YWFE