diff --git a/src/index.ts b/src/index.ts index a937afe..605ec48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,10 +22,17 @@ export default class AxiosWrapper { requests: CollectedRequestInfo[]; }; + protected readonly csrfHeaderName: string; + protected apiEndpoint?: string; constructor(options: AxiosWrapperOptions = {}) { - const {config = {}, apiEndpoint = '/api', collector = {}} = options; + const { + config = {}, + apiEndpoint = '/api', + collector = {}, + csrfHeaderName = 'X-CSRF-Token', + } = options; const axiosConfig: AxiosRequestConfig = { xsrfCookieName: '', @@ -43,6 +50,7 @@ export default class AxiosWrapper { errors: [], requests: [], }; + this.csrfHeaderName = csrfHeaderName; } setApiEndpoint = (endpoint = '') => { @@ -56,9 +64,9 @@ export default class AxiosWrapper { }; setCSRFToken = (token: string) => { - this._axios.defaults.headers.post['X-CSRF-Token'] = token; - this._axios.defaults.headers.put['X-CSRF-Token'] = token; - this._axios.defaults.headers.delete['X-CSRF-Token'] = token; + this._axios.defaults.headers.post[this.csrfHeaderName] = token; + this._axios.defaults.headers.put[this.csrfHeaderName] = token; + this._axios.defaults.headers.delete[this.csrfHeaderName] = token; }; setDefaultHeader = ({ diff --git a/src/models/index.ts b/src/models/index.ts index f9b8138..e471ca4 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -9,6 +9,7 @@ export interface AxiosWrapperOptions { config?: AxiosRequestConfig; apiEndpoint?: string; collector?: CollectorOptions; + csrfHeaderName?: string; } export interface CollectedRequestInfo {