React Configure proxy
Solution a: package. Json
Set the proxy properties directly in package.json
"Proxy" : "http://172.168.1.2:5000"Copy the code
Be sure to restart the React project after modifying the configuration
// NPM start NPM start // yarn Start yarn startCopy the code
Scheme 2: SRC/setupProxy. Js
1. Create the setupproxy. js file in the SRC directory
2. In the SRC file, place the following code
const { createProxyMiddleware } = require('http-proxy-middleware') module.exports = function (app) { App. use(createProxyMiddleware('/ API ', {target: 'http://172.168.1.2:5000', Secure: false, changeOrigin: true, pathRewrite: { "^/api": "/api" } })) }Copy the code
or
Be sure to restart the React project after modifying the configuration
// NPM start NPM start // yarn Start yarn startCopy the code