【发布时间】:2013-12-28 13:31:20
【问题描述】:
是否有可能,如果可以,如何使用grunt-contrib-connect 指定自定义标头?
【问题讨论】:
标签: gruntjs grunt-contrib-connect
是否有可能,如果可以,如何使用grunt-contrib-connect 指定自定义标头?
【问题讨论】:
标签: gruntjs grunt-contrib-connect
您可以编写自己的中间件并像这样指定req.headers:
grunt.initConfig({
connect: {
server: {
options: {
middleware: function(connect, options) {
return [
function(req, res, next) {
// If path has .json, accept json
if (url.parse(req.url).pathname.match(/\.json$/)) {
req.headers.accept = 'application/json';
}
next();
},
// then serve a static folder
connect.static('base/folder/')
]
},
}
}
},
});
【讨论】: