current position:Home>React configuration agent
React configuration agent
2022-04-29 06:22:01【Tool man of konjaku】
Method 1
stay package.json The following configuration is added in
"proxy":"http://localhost:5000"
Pay attention to !
// Local is 3000 Turn on
fetch('http://localhost:3000/*')
explain :
- advantage : Simple configuration , The front end can request resources without any prefix .
- shortcoming : Cannot configure multiple agents .
- Operation mode : Configure the agent as described above , When asked 3000 When there are no existing resources , Then the request will be forwarded to 5000 ( Priority matching front-end resources )
Method 2
First step : Create a proxy profile
stay src Create profile under :src/setupProxy.js
To write setupProxy.js Configure specific proxy rules :
const proxy = require('http-proxy-middleware') module.exports = function(app) { app.use( proxy('/api1', { //api1 It's a request that needs to be forwarded ( All with /api1 All prefix requests are forwarded to 5000) target: 'http://localhost:5000', // Configure forwarding destination address ( The address of the server that can return the data ) changeOrigin: true, // In the request header received by the control server host Value of field /* changeOrigin Set to true when , In the request header received by the server host by :localhost:5000 changeOrigin Set to false when , In the request header received by the server host by :localhost:3000 changeOrigin The default value is false, But we will generally changeOrigin Value to true */ pathRewrite: { '^/api1': ''} // Remove request prefix , Ensure that the normal request address is given to the background server ( You have to configure ) }), proxy('/api2', { target: 'http://localhost:5001', changeOrigin: true, pathRewrite: { '^/api2': ''} }) ) }
explain :
- advantage : Multiple agents can be configured , It can flexibly control whether the request goes through the proxy .
- shortcoming : Complicated configuration , Front end requests for resources must be prefixed .
copyright notice
author[Tool man of konjaku],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/116/202204260949129578.html
The sidebar is recommended
- Singleton mode - front end design mode
- QT sets that child elements do not inherit the parent style
- Using react to realize comment function
- Front end Vue template
- Front end vuejs set sail
- Front end Vue data binding and MVVM
- Vue data proxy and hijacking in front end
- Vue style of front end
- Front end Vue event handling
- Principle of Vue monitoring data change in front end
guess what you like
Vue calculation attribute and monitoring attribute of the front end
Front end Vue conditional rendering and list rendering
The front-end Vue collects form data
Vue built-in instruction of front end
Unknown HttpClient factory netty at org. openqa. selenium. remote...
Where is the user information obtained by the front end
What is the gutter principle of Ant Design Vue a-row
Element form account password
CSS to add horizontal lines around the text
Solution to vscode Vue project always reporting space or semicolon warning
Random recommended
- [entry DIARY 7 - ref of react]
- React - higher order functions and controlled components
- Calling setcookie in Ajax fails without any error in the IDE
- Differences, advantages and disadvantages between Ajax and Axios
- Choose Java or front-end for training and learning
- Simple sorting of JavaScript deep copy and shallow copy
- Analysis of event loop mechanism in JavaScript
- Epidemic prevention and control system of front and rear end separation based on Vue + nodejs
- Implementation of enterprise personnel management system by separating the front and back ends of springboot + Vue
- Vue difference between two arrays
- Vue openlayer add wind farm effect
- How to get child nodes of elements in HTML
- The file code with HTML suffix of vscode is not highlighted
- Use the table in Vue element admin in Vue admin template?
- [JavaScript] convert numerical value to numerical value
- Differences, advantages and disadvantages between Ajax and Axios
- Quietly tell you: the wrong place in react18 document
- The new smart spirit 1 starts in Asia! Breaking 100 in 6.7 seconds + frameless door, 190000 pre-sale
- Analysis of event loop mechanism in JavaScript
- Error occurred when installing vant on webstorm
- With the blessing of tinnove system, Changan uni-v does not have its own table
- Judging the application direction of small flat wire motor from SM 4x4 driverless technology verification vehicle
- Vue3 + nuxt3 build SSR website application, and realize server-side rendering from 0 to 1 without secret Fen sharing
- Vue3 + nuxt3 build SSR website application, and realize server-side rendering from 0 to 1 without secret Fen sharing
- Vue3 + nuxt3 build SSR website application, and realize server-side rendering from 0 to 1 without secret Fen sharing
- React bread crumbs
- HTTP network protocol
- Vue3 + nuxt3 build SSR website application, and realize server-side rendering from 0 to 1 without secret Fen sharing
- Vue3 + nuxt3 build SSR website application, and realize server-side rendering from 0 to 1 without secret Fen sharing
- Use of vuex
- Element UI El table modify input value view not updated
- Getsnapshotbeforeupdate example of react
- Recently, the MySQL server on the cloud was hacked. It took 20 minutes to modify the password after being mercilessly encrypted. This time I'll be hacked with your last name
- Java project: sporting goods Mall (java + springboot + jsp + HTML + Maven + MySQL)
- Java project: shared study room reservation management system (java + springboot + thymeleaf + HTML + Maven + MySQL)
- Java project: sporting goods Mall (java + springboot + jsp + HTML + Maven + MySQL)
- Java project: shared study room reservation management system (java + springboot + thymeleaf + HTML + Maven + MySQL)
- Sennheiser momentum true wireless 3 true wireless headphones will be available on May 10
- Coffeescript 2.7.0 release, JavaScript translation language
- Im instant messaging development: load balancing of high-performance HTTP server