The most recent project in the front and back is completely decoupled, with grunt management of the project. This can lead to a problem: cross-domain issues occur when the front-end interface is not on a server because it is being called at development time. However, it is not possible to implement a true cross-domain in either JSONP or Cros, as the project is actually published under the same server.
At this time our grunt-connect-proxy on the stage, it is specifically to solve the problem.
Specific configuration:
1. Download and install this component first
NPM Install Grunt-connect-proxy--save-dev
Here to note: Be sure to first install grunt-contrib-livereload this component, or grunt serve will always error
2. Add Configuration
var lrsnippet = require (' grunt-contrib-livereload/lib/utils '). Livereloadsnippet; var function (Connect, dir) { return connect.static (Require (' path '). Resolve (dir));}; var proxysnippet = require (' Grunt-connect-proxy/lib/utils '). Proxyrequest;
This break code should be added to the top of the gruntfile.js, module.exports above.
Then add proxy configuration and livereload configuration to connect
Connect: {options: {port:9000, open:true, Livereload:35729, //Change the "0.0.0.0" to access the server from outsideHostname: ' localhost '}, proxies: [{context:'/WebSite ', Host:' Www.somesite.com ', Port:80, https:false, Changeorigin:true}], Livereload: {options: {middleware :function(connect) {return[Lrsnippet, Mountfolder (Connect,'. tmp '), connect (). Use ('/bower_components ', connect.static ('./bower_components ')) , Mountfolder (Connect, Config.app), Proxysnippet, ]; } } },/***/}
Next, add proxy to this task serve
Grunt.task.run ([ ' clean:server ', ' WIREDEP ', ' Concurrent:server ', ' autoprefixer ', ' configureproxies ', // added to Livereload front ' connect:livereload ', ' watch ' ]);
OK, here is the agent added!
Reference:
Https://github.com/drewzboto/grunt-connect-proxy
http://fettblog.eu/blog/2013/09/20/using-grunt-connect-proxy/
Http://www.himysql.com/2014/07/29/grunt-connect-proxy-configure/
Http://www.ngnice.com/posts/76c4bd0f7a4cdc
Grunt-connect-proxy Resolving cross-domain issues during development