Nodejs Agent solves cross-domain problem of development environment

Source: Internet
Author: User

Cross-domain issues are encountered in the front-end separation project. The solution is nothing more than Jsonp cors.

The project front-end does not take the node service, the line with Nginx site, nginx forwarding Ajax request server.

Cross-domain issues for the local development environment use node as the proxy to forward the request server (a perfect solution to the cross-domain problem of requesting server in the development environment).

The node code is as follows

"Use strict"; Const Express = require (' Express '); Const PATH = require (' path '); const APP = Express (); Const REQUEST = require (' request ');//Configure the static file service middleware let serverurl= ' http://220.231.2.29:7668 ';//server address App.use (express.static (Path.join (__ DirName, './')));//static resource index.html and node code in a directory App.use ('/', function (req, res) {let  url = serverurl + req.url;  Req.pipe (Request (URL)). pipe (res);}); App.listen ("127.0.0.1", function () {//Front-end Ajax address write http://127.0.0.1:3000/  console.log (' server is running at Port 3000 ');});

Nodejs Agent solves cross-domain problem of development environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.