Thursday, 8 June 2017

Configuring gulp connect middleware for cross origin request access

My project's back-end part runs on http://localhost:8080 and front-end is running on gulp-connect server on http://localhost:8811.While running on chrome, whenever a REST api call is made, chrome generates this error message-

No 'Access-Control-Allow-Origin' header is present on the requested resource'

Can this error be removed using proxy configuration in gulp-connect's middleware options ? if yes then I want to know how. I tried setting a response header 'allow-origin' to 'http://localhost:8811' from back-end and it worked but i want to know if gulp can help remove that error.

Following is snippet from my gulpfile.js

gulp.task('webserver',function(){
    gulpWebServer.server({
        root : ['.'],
        port : 8811,
        host : 'gulp_dev',
        livereload : true,
        middleware: function(connect, opt) {
            return [
                proxy({ changeOrigin: true,target: 'http://localhost:8080'})
            ];
        }
    });
});



via Alok Mishra

No comments:

Post a Comment