A project that is separated from the front and back ends needs to address cross-domain issues in the development environment:
Reprint Link: https://www.cnblogs.com/ytu2010dt/p/5959899.html
1. Installing the Node environment
2. New JS file: Nodeproxy.js
Code:
"Use Strict"; Const Express= Require (' Express '); Const path= Require (' path '); Const app=Express (); Const request= Require (' request ')); //Configuring the static file Services middlewareLet Serverurl= ' http://220.231.2.29:7668 ';//Server AddressApp.use (Express.static (Path.join (__dirname, './'));//static resource index.html and node code in one directoryApp.use ('/',function(req, res) {Let URL= ServerURL +Req.url; Req.pipe (Request (URL)). pipe (res);}); App.listen (3000, ' 127.0.0.1 ',function() {//front-End Ajax address write Http://127.0.0.1:3000/Console.log (' server is running at Port 3000 ');});
3. Need to install Express and request:
NPM Install Express
NPM Install request
4. Run JS script node nodeproxy.js
node to do proxy forwarding request server, the project does not have to set up the front node service, you can solve the development environment of cross-domain problems;
Nodejs Agent solves cross-domain problem in development environment