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

How to obtain root permissions in a docker container

First, your container must be running You can vie...

How to check disk usage in Linux

1. Use the df command to view the overall disk us...

Vue uses vue-quill-editor rich text editor and uploads pictures to the server

Table of contents 1. Preparation 2. Define the gl...

Mysql date formatting and complex date range query

Table of contents Preface Query usage scenario ca...

Linux disk sequential writing and random writing methods

1. Introduction ● Random writing will cause the h...

Application of CSS3 animation effects in activity pages

background Before we know it, a busy year is comi...

Detailed explanation of how to use Teleport, a built-in component of Vue3

Table of contents 1. Teleport usage 2. Complete t...

Writing a web calculator using javascript

This article mainly records the effect of using j...

Detailed explanation of this reference and custom properties in JavaScript

Table of contents 1. this keyword 2. Custom attri...

Example of implementing skeleton screen with Vue

Table of contents Skeleton screen use Vue archite...