Problems with configuring request agents in react projects

the following code has been added to service.js

const proxy = require("http-proxy-middleware");//
const apiProxy = proxy("/api", {
        target: "https://api.douban.com",
        changeOrigin: false
    });
    app.use("/api", apiProxy);

image

http://localhost:8888/api/v2/music/search?q=%E5%91%A8%E6%9D%B0%E4%BC%A6&v=1526873684320
image


https://api.douban.com/v2/mus...

clipboard.png

Mar.12,2021

1. The picture given can only show 500error
2. Before using the proxy, try to see if the address after the proxy can be used, and then try to see if the address before the proxy can be used
3. If you have tried all of the above, then there is more than one picture. The problem of


has been solved. The location of this code for setting the proxy needs to be adjusted to before express processes the request

.
Menu