node.js - Please tell me, brothers, how to use http-proxy-middleware to make cross-domain post request backend on localhost.
为情所困
为情所困 2017-06-10 09:49:24
0
1
1115

During this period, when I was using related technologies to develop a small function, I encountered the problem of cross-port requesting the backend. I first read the official documentation, but I didn’t quite understand it. . . The specific situation is: I want to use ajax cross-domain request on the front-end page to the back-end server built by express. I checked some information and tried it myself, but I kept reporting various errors. . . It may be that I don't know how to configure http-proxy. Do I need to configure webpack and express backend at the same time?
The details are as follows:
First is the devServer part of webpack:

The second is the ajax request background in the js file:

Finally, the express backend:

In addition, according to the above writing method, ajax always reports 504 timeout, and at the same time, the background terminal also reports an error (probably corresponding to the 504 in the front desk), as shown below:

为情所困
为情所困

reply all(1)
習慣沉默

The first slash is not required when making an ajax request. It will be proxyed by devServer;

504 error code
http://www.checkupdown.com/st...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template