So. First time stuck with Netlify.
I created a Vue/Vite app and added a proxy setting to “hide” my real backend domain:
server: {
proxy: {
'/api': {
target: env.VITE_APP_BOOSTER_API,
changeOrigin: true,
secure:false,
//rewrite: (path) => path.replace(/^\/api/, ''),
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res, options) => {
proxyReq.setHeader('Cockpit-Token', env.VITE_APP_BOOSTER_API_TOKEN);
});
}
},
}
}
As far as I understood, the same is possible using the proxy settings, so i added to my netlify.toml:
[[redirects]]
from = "/api/*"
to = "API_URL/:splat"
status = 200
force = true
headers = {Cockpit-Token = "TOKEN"}
(in real file, the values are filled out with the same value as the env file)
When using my dev server, answer comes from the proxied API, returning the correct data.
Using the netlify proxy in build preview, i just get answered with an 302 from backend trying to redirect to a login page (which indicates that the access token is not sent correctly). What am I missing to make this work?