JS cross-domain solution react configuration reverse proxy

JS cross-domain solution react configuration reverse proxy

Cross-domain solutions

jsonp (simulate get)

CORS (Cross-Origin Resource Sharing)

acting

iframe

postMessage

window.name

WebSocket

React's proxy implements cross-domain

Configure in src/setupProxy.js file and install http-proxy-middleware, proxy middleware module through npm

Create src/setupProxy.js

Installing the Module

npm i -S http-proxy-middleware

const { createProxyMiddleware: proxy } = require('http-proxy-middleware')
module.exports = app => {
  app.use('/api', proxy({
    target: 'http://localhost',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }))
} 

The above is the details of JS cross-domain solution react configuration reverse proxy. For more information about react configuration reverse proxy, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • React build post-packaging and release summary
  • How to implement cors cross-domain request of fetch in react
  • Tutorial on how to configure React static pages with nginx
  • JS cross-domain solution: using CORS to achieve cross-domain

<<:  How to implement line breaks in textarea text input area

>>:  25 div+css programming tips and tricks

Recommend

Nginx location matching rule example

1. Grammar location [=|~|~*|^~|@] /uri/ { ... } 2...

A complete guide to the Docker command line (18 things you have to know)

Preface A Docker image consists of a Dockerfile a...

Application and implementation of data cache mechanism for small programs

Mini Program Data Cache Related Knowledge Data ca...

Docker deployment RabbitMQ container implementation process analysis

1. Pull the image First, execute the following co...

A brief summary of vue keep-alive

1. Function Mainly used to preserve component sta...

How to delete the container created in Docker

How to delete the container created in Docker 1. ...

The difference between char, varchar and text field types in MySQL

In MySQL, fields of char, varchar, and text types...

Docker Compose one-click ELK deployment method implementation

Install Filebeat has completely replaced Logstash...

Solution to the IP address not being displayed under Linux

Table of contents Preface Solution: Step 1 Step 2...

How to set underline in HTML? How to underline text in HTML

Underlining in HTML used to be a matter of enclos...

Detailed explanation of CSS3 rotating cube problem

3D coordinate concept When an element rotates, it...

JavaScript implements bidirectional linked list process analysis

Table of contents 1. What is a doubly linked list...

Summary of web designers' experience and skills in learning web design

As the company's influence grows and its prod...

Windows Server 2008 Tutorial on Monitoring Server Performance

Next, we will learn how to monitor server perform...