Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify headers with grunt-contrib-connect

Is it possible and if so how can one specify custom headers with grunt-contrib-connect?

like image 260
Brian M. Hunt Avatar asked Feb 13 '26 10:02

Brian M. Hunt


1 Answers

You can write your own middleware and specify req.headers like such:

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/')
                    ]
                },
            }
        }
    },
});
like image 123
Kyle Robinson Young Avatar answered Feb 20 '26 17:02

Kyle Robinson Young



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!