Amend CORS and NGINX
This commit is contained in:
46
src/main.ts
46
src/main.ts
@@ -23,11 +23,11 @@ import DecksView from "./views/deck/DecksView.vue";
|
||||
import DeckView from "./views/deck/DeckView.vue";
|
||||
import Callback from "./views/Callback.vue";
|
||||
import {useAuthStore} from "./stores/auth.ts";
|
||||
import axiosInstance from "./api";
|
||||
import SetsView from "./views/set/SetsView.vue";
|
||||
import JobsView from "./views/JobsView.vue";
|
||||
import {definePreset} from "@primeuix/themes";
|
||||
import {initConfig} from "@/util/config.ts";
|
||||
import {getConfig, initConfig} from "@/util/config.ts";
|
||||
import axios from "axios";
|
||||
|
||||
// Initialize configuration from window object
|
||||
initConfig((window as any).__APP_CONFIG__ || {})
|
||||
@@ -139,11 +139,43 @@ router.beforeEach(async (to) => {
|
||||
app.use(router);
|
||||
app.use(ToastService)
|
||||
|
||||
const deckService: DeckService = new DeckService(undefined, "/api", axiosInstance)
|
||||
const cardService: CardService = new CardService(undefined, "/api", axiosInstance)
|
||||
const setService: SetService = new SetService(undefined, "/api", axiosInstance)
|
||||
const cardPrintService: CardPrintService = new CardPrintService(undefined, "/api", axiosInstance)
|
||||
const jobService: JobService = new JobService(undefined, "/api", axiosInstance)
|
||||
console.log(getConfig().API_BASE_URL)
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: getConfig().API_BASE_URL ?? '',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
axiosInstance.interceptors.request.use(async (config) => {
|
||||
const user = await userManager.getUser()
|
||||
if (user?.access_token) {
|
||||
config.headers.Authorization = `Bearer ${user.access_token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
// Handle token expiration
|
||||
axiosInstance.interceptors.response.use(
|
||||
response => response,
|
||||
async (error) => {
|
||||
if (error.response?.status === 401) {
|
||||
await userManager.signinRedirect()
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
const deckService: DeckService = new DeckService(undefined, undefined, axiosInstance)
|
||||
const cardService: CardService = new CardService(undefined, undefined, axiosInstance)
|
||||
const setService: SetService = new SetService(undefined, undefined, axiosInstance)
|
||||
const cardPrintService: CardPrintService = new CardPrintService(undefined, undefined, axiosInstance)
|
||||
const jobService: JobService = new JobService(undefined, undefined, axiosInstance)
|
||||
|
||||
// @ts-ignore
|
||||
console.log(deckService.basePath)
|
||||
console.log(axiosInstance.defaults.baseURL)
|
||||
|
||||
app.provide(DeckServiceKey, deckService)
|
||||
app.provide(CardServiceKey, cardService)
|
||||
|
||||
Reference in New Issue
Block a user