Detailed explanation of Vue configuration request multiple server solutions

Detailed explanation of Vue configuration request multiple server solutions

1. Solution

1.1 Describing the interface context-path

The two backend interface service request prefixes are as follows:

  • Prefix 1: /bryant
  • Prefix 2: /

1.2 vue.config.js configuration

devServer: {
 port: 8005,
 proxy: {
  // First server configuration '/bryant': {
   target: 'http://localhost:8081,
   ws: true,
   changeOrigin: true,
   pathRewrite: {
    '^/bryant': '/bryant'
   }
  },
  // Second server configuration '/': {
   target: 'http://localhost:8082',
   ws: true,
   changeOrigin: true,
   pathRewrite: {
    '^/': '/'
   }
  } 
 }
} 

1.3 axios modification

// api base_url, set prefix does not exist const BASE_URL = ''
// Create an axios instance const service = axios.create({
 baseURL: BASE_URL, 
 timeout: 6000 // request timeout})

At this time, axios does not need to directly specify the baseUrl configuration

1.4 Sending a request

// The request prefix is ​​"/"
this.$http.get("/basketball").then(res => {
 console.log('/', res)
}).catch(err => {
 console.log(err)
})
// Request prefix is ​​"bryant"
this.$http.get("/bryant/mvp").then(res => {
 console.log('/bryant', res)
}).catch(err => {
 console.log(err)
})

Summarize

In the case of multiple interface services, if the prefix is ​​"/", it should be placed at the end of the proxy configuration. When proxying, it is searched from top to bottom. If it is placed at the top, other services will also be proxied by this configuration.

This is the end of this article about the detailed explanation of the solution of Vue configuration requesting multiple servers. For more relevant Vue configuration requesting multiple servers, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue configuration multi-proxy service interface address operation
  • Configuration method of packaging and deploying Vue project to IIS server
  • Detailed explanation of client (vue framework) and server (koa framework) communication and server cross-domain configuration

<<:  How to install Mysql5.7 in Centos6

>>:  How to set a fixed IP address in CentOS7 virtual machine

Recommend

100-1% of the content on the website is navigation

Website, (100-1)% of the content is navigation 1....

A brief discussion on the problem of Docker run container being in created state

In a recent problem, there is such a phenomenon: ...

How to define data examples in Vue

Preface In the development process, defining vari...

Nginx local directory mapping implementation code example

Sometimes you need to access some static resource...

Example of implementing dynamic verification code on a page using JavaScript

introduction: Nowadays, many dynamic verification...

Definition and usage of MySQL cursor

Creating a Cursor First, create a data table in M...

JavaScript plugin encapsulation for table switching

This article shares the encapsulation code of Jav...

How to use React to implement image recognition app

Let me show you the effect picture first. Persona...

Summary of pitfalls in importing ova files into vmware

Source of the problem As we all know, all network...

js implements single click to modify the table

Pure js implements a single-click editable table ...

Vue + element dynamic multiple headers and dynamic slots

Table of contents 1. Demand 2. Effect 3. All code...

Detailed analysis of the parameter file my.cnf of MySQL in Ubuntu

Preface Based on my understanding of MySQL, I thi...

How to install kibana tokenizer inside docker container

step: 1. Create a new docker-compose.yml file in ...

A few front-end practice summaries of Alipay's new homepage

Of course, it also includes some personal experien...