diff --git a/docker/Dockerfile b/docker/Dockerfile index 4a4d62e..d53cdf7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,7 +7,7 @@ COPY . . RUN npm run build # Stage 2: Create runtime image -FROM nginxinc/nginx-unprivileged:1.25-alpine +FROM nginxinc/nginx-unprivileged:1.25-alpine AS runtime # Create writable directories USER root diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d63031e..585f518 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/sh set -e +: "${API_BASE_URL:=http://localhost:7070}" # Create runtime config file in writable location cat > /runtime-config/config.js < { - 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) - } -) - -export default axiosInstance; \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 215d19d..881d34f 100644 --- a/src/main.ts +++ b/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) diff --git a/src/util/config.ts b/src/util/config.ts index 1e4cc93..e243904 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -1,11 +1,9 @@ export interface AppConfig { API_BASE_URL: string; - OTHER_VAR: string; } let runtimeConfig: AppConfig = { - API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '', - OTHER_VAR: import.meta.env.VITE_OTHER_VAR || '' + API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '' }; export function initConfig(config: Partial) {