Amend Upstream URL

This commit is contained in:
2025-07-15 18:05:11 +02:00
parent 53fc2ed8fb
commit 202959dd9e
5 changed files with 20 additions and 14 deletions

View File

@@ -1,17 +1,19 @@
#!/bin/sh #!/bin/sh
set -e set -e
: "${API_BASE_URL:=http://localhost:7070}" : "${API_BASE_URL:=http://localhost}"
: "${API_PORT:=7070}"
# Create runtime config file in writable location # Create runtime config file in writable location
cat > /runtime-config/config.js <<EOF cat > /runtime-config/config.js <<EOF
window.__APP_CONFIG__ = { window.__APP_CONFIG__ = {
API_BASE_URL: "${API_BASE_URL}" API_BASE_URL: "${API_BASE_URL}",
API_PORT: "${API_PORT}"
}; };
EOF EOF
# Generate nginx config from template (if using) # Generate nginx config from template (if using)
if [ -f "/etc/nginx/templates/nginx.conf.template" ]; then if [ -f "/etc/nginx/templates/nginx.conf.template" ]; then
envsubst '${API_BASE_URL}' \ envsubst '${API_BASE_URL} ${API_PORT}' \
< /etc/nginx/templates/nginx.conf.template \ < /etc/nginx/templates/nginx.conf.template \
> /etc/nginx/nginx.conf > /etc/nginx/nginx.conf
fi fi

View File

@@ -28,7 +28,7 @@ http {
resolver 127.0.0.11 valid=10s ipv6=off; resolver 127.0.0.11 valid=10s ipv6=off;
upstream backend { upstream backend {
server ${API_BASE_URL}; server ${API_BASE_URL}:${API_PORT};
} }
server { server {

View File

@@ -1,3 +1,4 @@
window.__RUNTIME_CONFIG__ = { window.__RUNTIME_CONFIG__ = {
API_BASE_URL: "__API_BASE_URL__" API_BASE_URL: "__API_BASE_URL__",
API_PORT: "__API_PORT__"
}; };

View File

@@ -26,7 +26,7 @@ import {useAuthStore} from "./stores/auth.ts";
import SetsView from "./views/set/SetsView.vue"; import SetsView from "./views/set/SetsView.vue";
import JobsView from "./views/JobsView.vue"; import JobsView from "./views/JobsView.vue";
import {definePreset} from "@primeuix/themes"; import {definePreset} from "@primeuix/themes";
import {getConfig, initConfig} from "@/util/config.ts"; import {getApiUrl, initConfig} from "@/util/config.ts";
import axios from "axios"; import axios from "axios";
// Initialize configuration from window object // Initialize configuration from window object
@@ -139,10 +139,8 @@ router.beforeEach(async (to) => {
app.use(router); app.use(router);
app.use(ToastService) app.use(ToastService)
console.log(getConfig().API_BASE_URL)
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: getConfig().API_BASE_URL ?? '', baseURL: getApiUrl() ?? '',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
@@ -173,10 +171,6 @@ const setService: SetService = new SetService(undefined, undefined, axiosInstanc
const cardPrintService: CardPrintService = new CardPrintService(undefined, undefined, axiosInstance) const cardPrintService: CardPrintService = new CardPrintService(undefined, undefined, axiosInstance)
const jobService: JobService = new JobService(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(DeckServiceKey, deckService)
app.provide(CardServiceKey, cardService) app.provide(CardServiceKey, cardService)
app.provide(SetServiceKey, setService) app.provide(SetServiceKey, setService)

View File

@@ -1,9 +1,11 @@
export interface AppConfig { export interface AppConfig {
API_BASE_URL: string; API_BASE_URL: string;
API_PORT: number;
} }
let runtimeConfig: AppConfig = { let runtimeConfig: AppConfig = {
API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '' API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '',
API_PORT: import.meta.env.VITE_API_BASE_URL || 8080
}; };
export function initConfig(config: Partial<AppConfig>) { export function initConfig(config: Partial<AppConfig>) {
@@ -16,3 +18,10 @@ export function initConfig(config: Partial<AppConfig>) {
export function getConfig(): AppConfig { export function getConfig(): AppConfig {
return runtimeConfig; return runtimeConfig;
} }
export function getApiUrl() {
if (!runtimeConfig.API_BASE_URL) {
return null;
}
return `${runtimeConfig.API_BASE_URL}:${runtimeConfig.API_PORT}`;
}