mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: cors enabled for desktop mode
This commit is contained in:
@@ -7,16 +7,17 @@ const headers = {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
const baseUrl =
|
||||
process.env.NODE_ENV === 'development' ? 'http://localhost:5000' : undefined
|
||||
const getAuthCode = async (credentials: any) => {
|
||||
return fetch('/SASjsApi/auth/authorize', {
|
||||
return fetch(`${baseUrl}/SASjsApi/auth/authorize`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(credentials)
|
||||
}).then((data) => data.json())
|
||||
}
|
||||
const getTokens = async (payload: any) => {
|
||||
return fetch('/SASjsApi/auth/token', {
|
||||
return fetch(`${baseUrl}/SASjsApi/auth/token`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(payload)
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user