2

I've got the following vue.config.js in my Vue project:

module.exports = {
    devServer: {
        proxy: {
            '^/api/': {
                target: 'https://example.com/api/',
                changeOrigin: true,
                logLevel: 'debug'
            },
        }
    }
}

So all requests to /api/* should be redirected to https://example.com/api/*. Unfortunately, the proxy seems to remove parts of the URL coming after api/:

[HPM] POST /api/api-token-auth/ -> https://example.com/api/

What happened to the api-token-auth/ part?

1 Answer 1

1

To proxy all requests to /api according to the syntax in the docs, create the rule as follows:

module.exports = {
    devServer: {
        proxy: {
            '/api': {
                target: 'https://example.com',
                changeOrigin: true,
                logLevel: 'debug'
            },
        }
    }
}

You shouldn't put the /api path again in target because everything after and including /api from your original route will be appended onto the target.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, works like a charm. Sometimes one doesn't spot the obvious...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.