Dev server: Initial call to backend to get cookies #6521
Open
Description
Clear and concise description of the problem
I'm missing cookies (for example JSESSIONID, X-XRSF-TOKEN) when I use the dev server (localhost:3000). This makes the first POST request fail since there is no xsrf-token. Having no session can also cause problems in application logic.
Suggested solution
Vite should, at the beginning of accessing the website, make a call to the backend server and proxy the cookies to the browser.
The backend server URL is specified by server.proxy.init.
Optional: Values in mappings can now be replaced with ^ to use the value of server.proxy.init.
vite.conf.js
{
server: {
proxy: {
init: "http://localhost:8081",
mappings: {
"/api": "^"
}
}
}
}
Alternative
Currently I am using this workaround:
I created a dummy GET endpoint that doesn't return anything, just to call it and get the cookies.
export default {
name: "App",
components: {
//...
},
setup() {
//...
if (window.location.href === 'http://localhost:3000/') {
axios.get("/api/xsrf")
}
return {
//...
}
}
}
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.