node.js - forwarding grunt connect to different url -
node.js - forwarding grunt connect to different url -
i'm using grunt connect livereload dev environment.
i want able phone call production api under /server.
to need direct calls
http://localhost:9000/server
to
http://www.production-server.com/server
this me because want test against production server when in dev mode.
here's current connect configuration (generated yeoman):
class="snippet-code-js lang-js prettyprint-override">connect: { options: { port: 9000, // alter '0.0.0.0' access server outside. hostname: 'localhost', livereload: 35729 }, livereload: { options: { open: true, middleware: function(connect, options, middlewares) { homecoming [ connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appconfig.app) ]; } } }, test: { options: { port: 9001, middleware: function(connect) { homecoming [ connect.static('.tmp'), connect.static('test'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appconfig.app) ]; } } }, dist: { options: { open: true, base: '<%= yeoman.dist %>' } } },
i've found problem , solution:
first thing utilize the: grunt-connect-proxy grunt task able proxy (you can there). configuration not obvious, can find info (and example) here: https://www.npmjs.org/package/grunt-connect-proxy
my specific problem because server did not take calls did not come same domain, did add together "headers" property config domain name. how new config should like:
connect: { options: { port: 9000, // alter '0.0.0.0' access server outside. hostname: 'localhost', livereload: 35729 }, server: { proxies: [ { context: '/server', host: 'production-server.com', post: 80, changeorigin: true, headers: { host: 'simple-layout.com' } } ] }, livereload: { options: { open: true, middleware: function (connect) { homecoming [ proxysnippet, connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appconfig.app) ]; } } }, test: { options: { port: 9001, middleware: function (connect) { homecoming [ connect.static('.tmp'), connect.static('test'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appconfig.app) ]; } } }, dist: { options: { open: true, base: '<%= yeoman.dist %>' } } },
node.js gruntjs grunt-contrib-connect
Comments
Post a Comment