内容类型处理多种内容类型例子
var http = create('http');
var contentTypes = require('content-types');
http.createServer(function (req, res) {
contentTypes(req, {
'text/html': returnHtml,
'application/javascript': returnJson
})(req, res);
}).listen(8080);
function returnHtml(req, res) {
res.end('- bar
- bar
');
}
function returnJson(req, res) {
res.end(JSON.stringify({ bar: 'bar' }));
}
暂无评论