axios-module
axios-module copied to clipboard
setting baseUrl base on req.headers.host or req.headers['x-forwarded-host']
Hi, I'm running NUXT in SSR mode with multiple domains. What I'm trying to achieve is to set the base url based on the request headers in order for the backend to return the right response. Another solution that I thought about it to send the request with x-forwarded-host header to the backend but again I don't know how to set it dynamically to all requests based on the headers.
Any help would be appreciated
Hey,
Sorry for the late response.
You can create a custom plugin and and modify axios headers.
// ~/plugins/some-plugin.js
export default function (ctx, inject) {
if (process.server) {
// use `ctx.req` to extract host
} else {
// plugin runs on client side, use `window.location` to extract host
}
}
Checkout module docs to see how to change baseURL and more