M
M
mrFlyer2019-08-22 11:08:02
Vue.js
mrFlyer, 2019-08-22 11:08:02

Why doesn't the proxy rule work in NuxtJS+Axios?

I'm trying to use a third party API in my NuxtJS project. There was a problem of cross-domain requests, as I understand it, you can use @nuxtjs/proxy to solve them.
I make a config according to the documentation:

require('dotenv').config();

export default {
    mode: 'universal',
    plugins: [],
    buildModules: [],
    modules: [
        '@nuxtjs/axios',
        '@nuxtjs/proxy',
        ['@nuxtjs/dotenv', { systemvars: true }],
    ],
    axios: {
        proxy: true,
    },
    proxy: {
        '/api': {
            target: "http://custom-service.com",
            pathRewrite: {
                '^/api' : ""
            },
        },
    },
}

In the component I use
export default {
    created() {
        this.$axios.get("/api/places");
    }
}

If I understand correctly, then the request
localhost:3003/api/places should be replaced with custom-service.com/places
But this does not happen, in the browser logs it continues to knock on localhost:3003/api/places
Tell me what I'm doing wrong So?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrFlyer, 2019-08-22
@mrFlyer

Hmm =)....
In the browser logs, it appears and should show localhost:3003/api/places, but in fact the request is made by the correct link. I even thought that he logs should show the real link on which the request goes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question