• The installation

Notes:

This middleware is only used at development time, so it is installed in devDependencies and not packaged into the project;

Online projects should be configured on the Nginx server

// This middleware is only used for development purposes, so it is installed in devDependencies and not packaged into the project; NPM install --save-dev http-proxy-middleware should be installed on the nginx serverCopy the code
  • use

Create setupproxy. js in SRC. In node_modules, there is a webpack.config.js file in the react-scripts package.

There is a string of code that determines the name and location of the configuration file

‘! * * / SRC/setupProxy. * ‘

const {createProxyMiddleware} = require('http-proxy-middleware'); Module. exports = function(app) {app. Use (createProxyMiddleware('/portal', {target: 'HTTP: 106.75.95.89:90008')); } app.use can be configured with multiple domains;Copy the code

Questions and doubts

Const express = require('express'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); app.use('/api', createProxyMiddleware( { target: 'http://www.example.org', changeOrigin: true }) ); app.listen(3000); There is no such usage as above, app is exposed through moudle, but generated through Express, I follow the official writing method, error; The require of (...). I didn't find a similar question online either; I looked at the pakage.json file in the HTTP-proxy-middleware package in node_modules and saw that express had been introduced; React is still working on it, thank you!!Copy the code