Answer a question

I have a vue cli 3.5.0 project and am trying to add a proxy, but i cant get it to work. the server runs on :5000 and the client on :8080. Below you can see my proxy. But it keeps using :8080 instead of :5000

vue.config.js

module.exports = {
    devServer: {
      proxy: {
        '/api': {
          target: 'http://localhost:5000',
          ws: true,
          changeOrigin: true
        }
      }
    }
  }

And this is an example of how I call a request

const url = '/api/races/'
const config = {
    headers: {'Authorization': "Bearer " + localStorage.token}
}

class RaceService {
    // Get Races
    static getRaces() {
        return new Promise(async (resolve, reject) => {
            try {
                const res = await axios.get(url)
                const races = res.data
                resolve(races)
            } catch (err) {
                reject(err)
            }
        })
    }
}

Can someone maybe help me? the api requests need to use :5000 instead of :8080

Answers

You'll have to use "^/api" instead of "/api"

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐