1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-03 21:10:05 +00:00

fix: cors enabled for desktop mode

This commit is contained in:
Saad Jutt
2021-11-13 23:29:27 +05:00
parent cbe07b4abb
commit 2bb10c7166
6 changed files with 47 additions and 28 deletions

View File

@@ -43,15 +43,18 @@ export default function useTokens() {
}
}
// const baseUrl = 'http://localhost:5000'
// const isAbsoluteURLRegex = /^(?:\w+:)\/\//
const baseUrl =
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
const isAbsoluteURLRegex = /^(?:\w+:)\/\//
const setAxiosRequestHeader = (accessToken: string) => {
axios.interceptors.request.use(function (config: any) {
// if (!isAbsoluteURLRegex.test(config.url)) {
// config.url = baseUrl + config.url
// }
config.headers.Authorization = `Bearer ${accessToken}`
axios.interceptors.request.use(function (config) {
if (baseUrl && !isAbsoluteURLRegex.test(config.url as string)) {
config.url = baseUrl + config.url
}
config.headers!['Authorization'] = `Bearer ${accessToken}`
config.withCredentials = true
return config
})