[react] Create and start the react project and cross-domain proxy:


1. Create and start the react project:

npx create-react-app 项目名        //创建
npm install                       //安装依赖
npm start                         //启动

2. Cross-domain proxy:

[1] Documentation: https://create-react-app.dev/docs/proxying-api-requests-in-development/
npm install http-proxy-middleware --save
【2】src/setupProxy.js:
const {
    
     createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
    
    
  app.use(
    '/ajax',
    createProxyMiddleware({
    
    
      target: 'https://m.maoyan.com',
      changeOrigin: true,
    })
  );
  app.use(
    '/api',
    createProxyMiddleware({
    
    
      target: 'https://i.maoyan.com',
      changeOrigin: true,
    })
  );
};

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_53791978/article/details/131569583