A
A
Analka2021-08-18 16:08:56
proxy
Analka, 2021-08-18 16:08:56

Why doesn't it remove the prefix from the url Axios + Proxy?

Nuxt project

in nuxt.config.js

axios: {
    proxy: true,
    debug: true,
    browserBaseURL: '/api',
  },

  proxy: {
    '/api': {
      target: process.env.API_URL,
      changeOrigin: true,
      pathRewrite: {
        '^/api': '',
      },
    },
  },

when I send such request to api

$axios
          .$get(`/v1/autocomplete`, {
            params: {
              address: inputSearch.value,
            },
          })
          .then((response: any) => {
            isAutocomplete.value = true
            autocomplete.value = response.result
          })
          .catch((error: any) => {
            console.log(error)
          })

api is not removed from the address

Request URL: http://127.0.0.1:3000/api/v1/autocomplete?address=asdasd

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Iamman, 2021-08-18
@Iamman

Why do you need browserBaseURL here? Try without it, it should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question