mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
26 lines
593 B
TypeScript
26 lines
593 B
TypeScript
![]() |
/**
|
||
|
* Module: communication setup.
|
||
|
*/
|
||
|
import axios from 'axios';
|
||
|
|
||
|
import { buildConstants } from '@/utils/buildConstants';
|
||
|
|
||
|
const defaultOptions = {
|
||
|
xsrfCookieName: 'csrftoken',
|
||
|
xsrfHeaderName: 'x-csrftoken',
|
||
|
baseURL: `${buildConstants.backend}`,
|
||
|
withCredentials: true
|
||
|
};
|
||
|
|
||
|
export const axiosInstance = axios.create(defaultOptions);
|
||
|
axiosInstance.interceptors.request.use(config => {
|
||
|
const token = document.cookie
|
||
|
.split('; ')
|
||
|
.find(row => row.startsWith('csrftoken='))
|
||
|
?.split('=')[1];
|
||
|
if (token) {
|
||
|
config.headers['x-csrftoken'] = token;
|
||
|
}
|
||
|
return config;
|
||
|
});
|