mirror of https://github.com/rancher/dashboard.git
32 lines
951 B
JavaScript
32 lines
951 B
JavaScript
import https from 'https';
|
|
import { CSRF } from '@shell/config/cookies';
|
|
|
|
export default function({
|
|
$axios, $cookies, isDev, req
|
|
}) {
|
|
$axios.defaults.headers.common['Accept'] = 'application/json';
|
|
$axios.defaults.withCredentials = true;
|
|
|
|
$axios.onRequest((config) => {
|
|
const csrf = $cookies.get(CSRF, { parseJSON: false });
|
|
|
|
if ( csrf ) {
|
|
config.headers['x-api-csrf'] = csrf;
|
|
}
|
|
});
|
|
|
|
if ( isDev ) {
|
|
// https://github.com/nuxt-community/axios-module/blob/dev/lib/module.js#L78
|
|
// forces localhost to http, for no obvious reason.
|
|
// But we never have any reason to talk to anything plaintext.
|
|
if ( $axios.defaults.baseURL.startsWith('http://') ) {
|
|
$axios.defaults.baseURL = $axios.defaults.baseURL.replace(/^http:/, 'https:');
|
|
}
|
|
|
|
const insecureAgent = new https.Agent({ rejectUnauthorized: false });
|
|
|
|
$axios.defaults.httpsAgent = insecureAgent;
|
|
$axios.httpsAgent = insecureAgent;
|
|
}
|
|
}
|