Gulp – connect proxy example

It will avoid CORS problem during development.

var Proxy = require('gulp-connect-proxy');
...
// A local web server for dev convenience
gulp.task("server", function() {
	connect.server({
	  root: "./dist",
	  port: 22532,
          middleware: function (connect, opt) {
	      opt.route = '/proxy';
	      var proxy = new Proxy(opt);
	      return [proxy];
	  }
	});
});

Example of calling API

return $http.get(
             
  'http://localhost:22532/proxy/external.host.com:8080/api/myservice/myid', 
                    
  { params: { metricSelector: "hello2"} }
);

Gulp connect web site

https://www.npmjs.com/package/gulp-connect-proxy

Advertisements
This entry was posted in Programming, Web and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s