gruntjs / grunt-contrib-connect

Start a static web server.
http://gruntjs.com
MIT License
714 stars 146 forks source link

middleware is not properly setting the header #194

Closed amir-rahnama closed 5 years ago

amir-rahnama commented 8 years ago
grunt@0.4.5
grunt-contrib-connect@0.10.1
grunt-contrib-watch@0.6.1

Here is my config file but for some strange reasons,

connect: {
        server: {
            options: {
                port: 9001,
                base: '.',
                open: true,
                livereload: true, 
                middleware: function(connect, options, middlewares) {
                    middlewares.unshift(function(req, res, next) {
                        res.setHeader('Access-Control-Allow-Origin', '*');
                        next();
                    });

                    return middlewares;
                },
            },
        }
    }`

although the code gets executed, the requests still don't have the headers.

yingnansong commented 8 years ago

Change your middleware function from function(req, res, next) { res.setHeader('Access-Control-Allow-Origin', '*'); next(); } to function(req, res, next) { res.setHeader('Access-Control-Allow-Origin', '*'); return next(); }