- axios config for cors

This commit is contained in:
Arno Kaimbacher 2021-11-17 12:03:44 +01:00
parent 1660bc6830
commit 39d323b619
8 changed files with 1198 additions and 1262 deletions

View file

@ -1,7 +1,13 @@
import axios, { AxiosRequestConfig, AxiosInstance, AxiosPromise } from "axios";
const initialization = (config: AxiosRequestConfig): AxiosInstance => {
axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
//axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
delete axios.defaults.headers.common["X-Requested-With"];
// axios.defaults.withCredentials = true;
// const token = document.head.querySelector('meta[name="csrf-token"]');
// if (token) {
// axios.defaults.headers.common["X-CSRF-TOKEN"] = token.innerHTML;
// }
const axiosInstance = axios.create(config);
/*

View file

@ -4,7 +4,12 @@ import * as qs from "qs";
export const axiosRequestConfiguration: AxiosRequestConfig = {
responseType: "text",
headers: {
"Content-Type": "application/json",
// "Content-Type": "text/plain",
"Content-Type": "application/x-www-form-urlencoded",
// "Content-Type": "application/x-www-form-urlencoded",
// credentials: "same-origin",
// "Access-Control-Allow-Credentials": "true",
// "Access-Control-Allow-Origin": "*",
},
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
};