使用grunt-contrib-connect指定标头

时间:2013-12-10 20:27:02

标签: gruntjs grunt-contrib-connect

是否可以,如果可以,如何使用grunt-contrib-connect指定自定义标头?

1 个答案:

答案 0 :(得分:5)

您可以编写自己的中间件并指定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/')
                    ]
                },
            }
        }
    },
});
相关问题