G
G
goodden12019-11-09 22:10:00
JavaScript
goodden1, 2019-11-09 22:10:00

How to use Nuxt proxy for all axios requests?

hosted on heroku on different front and back domains.
making requests for backing blocks cors. I connected a proxy for nuxt,
but I just can’t figure out how it works.
i need any axios request to be redirected to the api domain....
so far my nuxt.config.js looks like this

modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/auth',
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxtjs/proxy'
  ],
  axios: {
    proxy: true,
    proxyHeaders:false,
  },
  proxy: {
        '/api': {
      target: 'https://api-for-blog.herokuapp.com/api',
      changeOrigin: false,
      pathRewrite: {
        '^/api' : '/'
      }
    }
  },
  // axios: {
  //   proxy: true
  // },
  //
  // proxy: {
  //   '/api/': { target: 'https://api-for-blog.herokuapp.com/api', pathRewrite: {'^/api/': ''},changeOrigin: true }
  // },
  auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: "api/login", method: "post", propertyName: "meta.token" },
          user: { url: "api/user", method: "get", propertyName: "data" },
          logout: { url: api/logout", method: "post" },
        },
      }
    },
    watchLoggedIn: true,
    rewriteRedirects: true
  },

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxC, 2020-05-09
@MaxC

How did you solve the problem?

M
Mixonic, 2021-05-08
@Mixonic

https://dev.to/bosemian/avoid-cors-in-nuxt-js-with...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question