cn-request
Advanced tools
Comparing version 1.0.31 to 1.0.32
@@ -92,2 +92,16 @@ (function (global, factory) { | ||
} | ||
function getCookie(cookieName) { | ||
var allCookies = window.document.cookie; | ||
var cookiePos = allCookies.indexOf(cookieName); | ||
var cookieVal = ""; | ||
if (cookiePos != -1) { | ||
cookiePos = cookiePos + cookieName.length + 1; | ||
var cookieEnd = allCookies.indexOf(";", cookiePos); | ||
if (cookieEnd == -1) { | ||
cookieEnd = allCookies.length; | ||
} | ||
cookieVal = allCookies.substring(cookiePos, cookieEnd); | ||
} | ||
return cookieVal; | ||
} | ||
@@ -194,2 +208,10 @@ var LEGAL_METHODS = ["GET", "POST"]; | ||
var axiosInstance = axios.create(axiosConfig); | ||
try { | ||
var xsrfToken = getCookie('XSRF-TOKEN'); | ||
if (!xsrfToken) { | ||
axiosInstance.defaults.headers.common['X-XSRF-TOKEN'] = xsrfToken; | ||
} | ||
} | ||
catch (error) { | ||
} | ||
axiosInstance.interceptors.request.use(function (config) { | ||
@@ -196,0 +218,0 @@ try { |
{ | ||
"name": "cn-request", | ||
"version": "1.0.31", | ||
"version": "1.0.32", | ||
"description": "菜鸟前端统一请求库", | ||
@@ -5,0 +5,0 @@ "author": "牛尔", |
@@ -11,3 +11,3 @@ /** | ||
} from "axios"; | ||
import { isUndefined, armsTraceLog, mergeReportData } from "./utils"; | ||
import { isUndefined, armsTraceLog, mergeReportData, getCookie } from "./utils"; | ||
import { | ||
@@ -185,2 +185,13 @@ CnOptions, | ||
const axiosInstance: AxiosInstance = axios.create(axiosConfig); | ||
// 全局 xsrfToken 处理 | ||
try { | ||
const xsrfToken = getCookie('XSRF-TOKEN'); | ||
if(!xsrfToken){ | ||
axiosInstance.defaults.headers.common['X-XSRF-TOKEN'] = xsrfToken; | ||
} | ||
} catch (error) { | ||
} | ||
axiosInstance.interceptors.request.use( | ||
@@ -187,0 +198,0 @@ (config: AxiosRequestConfig) => { |
@@ -80,2 +80,18 @@ import { AxiosResponse } from "axios"; | ||
export { isUndefined, mergeReportData, armsTraceLog }; | ||
function getCookie(cookieName: string): string { | ||
const allCookies: string = window.document.cookie; | ||
let cookiePos = allCookies.indexOf(cookieName); | ||
let cookieVal = ""; | ||
if (cookiePos != -1) { | ||
cookiePos = cookiePos + cookieName.length + 1; | ||
let cookieEnd = allCookies.indexOf(";", cookiePos); | ||
if (cookieEnd == -1) { | ||
cookieEnd = allCookies.length; | ||
} | ||
cookieVal = allCookies.substring(cookiePos, cookieEnd); | ||
} | ||
return cookieVal; | ||
} | ||
export { isUndefined, mergeReportData, armsTraceLog, getCookie }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73980
674