【问题标题】:Specify headers with grunt-contrib-connect使用 grunt-contrib-connect 指定标头
【发布时间】:2013-12-28 13:31:20
【问题描述】:

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

【问题讨论】:

    标签: gruntjs grunt-contrib-connect


    【解决方案1】:

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

    【讨论】:

    • 就是这样。谢谢,凯尔。
    猜你喜欢
    • 2015-01-25
    • 2014-11-19
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多