Amend CORS and NGINX

This commit is contained in:
2025-07-15 17:33:39 +02:00
parent 8c9d38de35
commit fc95c3fdfd
7 changed files with 46 additions and 46 deletions

View File

@@ -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

View File

@@ -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 <<EOF
window.__APP_CONFIG__ = {

View File

@@ -26,7 +26,7 @@ http {
}
upstream backend {
server localhost:8080;
server ${API_BASE_URL}:8080;
}
server {
@@ -54,9 +54,9 @@ http {
access_log off;
}
location /api/ {
location ^~ /api/ {
# Proxy to Quarkus
proxy_pass http://backend/;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

View File

@@ -1,3 +1,3 @@
window.__RUNTIME_CONFIG__ = {
API_URL: "__API_URL__"
API_BASE_URL: "__API_BASE_URL__"
};

View File

@@ -1,31 +0,0 @@
import axios from "axios";
import {userManager} from "../stores/auth.ts";
import {getConfig} from "@/util/config.ts";
const axiosInstance = axios.create({
baseURL: getConfig().API_BASE_URL || '/api',
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)
}
)
export default axiosInstance;

View File

@@ -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)

View File

@@ -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<AppConfig>) {