mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-07-26 23:25:22 +00:00
runtime base url injection
This commit is contained in:
parent
fad981aa43
commit
7a68e5c27a
@ -6,5 +6,13 @@ VITE_API_BASE_URL=${VITE_API_BASE_URL:-"http://backend:8080"}
|
||||
# Replace the placeholder in nginx.conf with the actual backend URL
|
||||
sed -i "s|\${VITE_API_BASE_URL}|${VITE_API_BASE_URL}|g" /etc/nginx/nginx.conf
|
||||
|
||||
# Inject runtime configuration into config.js
|
||||
cat > /usr/share/nginx/html/config.js << EOF
|
||||
// Runtime configuration - injected at container startup
|
||||
window.runtimeConfig = {
|
||||
apiBaseUrl: '${VITE_API_BASE_URL}'
|
||||
};
|
||||
EOF
|
||||
|
||||
# Start nginx
|
||||
exec nginx -g "daemon off;"
|
@ -12,11 +12,12 @@
|
||||
<link rel="apple-touch-icon" href="/logo192.png" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
|
||||
<title>Vite App</title>
|
||||
<title>Stirling-PDF</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<script src="/config.js"></script>
|
||||
<script type="module" src="/src/index.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
4
frontend/public/config.js
Normal file
4
frontend/public/config.js
Normal file
@ -0,0 +1,4 @@
|
||||
// Runtime configuration - injected at container startup
|
||||
window.runtimeConfig = {
|
||||
apiBaseUrl: 'http://localhost:8080'
|
||||
};
|
@ -1,14 +1,14 @@
|
||||
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080';
|
||||
|
||||
// Runtime configuration access
|
||||
declare global {
|
||||
interface Window {
|
||||
runtimeConfig?: {
|
||||
apiBaseUrl?: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const makeApiUrl = (endpoint: string): string => {
|
||||
const baseUrl = apiBaseUrl;
|
||||
|
||||
// If baseUrl is empty (development), return endpoint as-is for proxy
|
||||
if (!baseUrl) {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
const baseUrl = window.runtimeConfig?.apiBaseUrl || 'http://localhost:8080';
|
||||
// For production, combine base URL with endpoint
|
||||
return `${baseUrl}${endpoint}`;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user