mirror of https://github.com/rancher/dashboard.git
Pass cookies through on SSR requests
This commit is contained in:
parent
ab4ee15cb1
commit
1fbe9df5de
|
|
@ -6,21 +6,30 @@ export default function({
|
|||
$axios, $cookies, isDev, req
|
||||
}) {
|
||||
$axios.defaults.headers.common['Accept'] = 'application/json';
|
||||
$axios.defaults.xsrfCookieName = 'CSRF';
|
||||
$axios.defaults.xsrfHeaderName = 'X-Api-Csrf';
|
||||
$axios.defaults.withCredentials = true;
|
||||
|
||||
if ( process.server ) {
|
||||
$axios.defaults.headers.common['user-agent'] = `Dashboard (Mozilla) v${ pkg.version }`;
|
||||
$axios.defaults.headers.common['access-control-expose-headers'] = `set-cookie`;
|
||||
|
||||
// For requests from the server, set the base URL to the URL that the request came in on
|
||||
$axios.onRequest((config) => {
|
||||
const csrf = $cookies.get('CSRF');
|
||||
|
||||
if ( csrf ) {
|
||||
config.headers['x-api-csrf'] = csrf;
|
||||
}
|
||||
|
||||
if ( process.server ) {
|
||||
config.headers.common['access-control-expose-headers'] = `set-cookie`;
|
||||
config.headers.common['user-agent'] = `Dashboard (Mozilla) v${ pkg.version }`;
|
||||
|
||||
if ( req.headers.cookie ) {
|
||||
config.headers.common['cookies'] = req.headers.cookie;
|
||||
}
|
||||
|
||||
if ( config.url.startsWith('/') ) {
|
||||
config.baseURL = `${ req.protocol || 'https' }://${ req.headers.host }`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ( process.server ) {
|
||||
$axios.onResponse((res) => {
|
||||
const parsed = setCookieParser(res.headers['set-cookie'] || []);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue