Try fix dynamic env
This commit is contained in:
parent
a26902e414
commit
6e55b088e9
Binary file not shown.
@ -14,7 +14,6 @@ router = APIRouter()
|
|||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=["*"],
|
||||||
allow_credentials=True,
|
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|||||||
4
frontend/10-generate-env.sh
Normal file
4
frontend/10-generate-env.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Generate env.js from the template
|
||||||
|
envsubst < /etc/env/env.js.template > /usr/share/nginx/html/env.js
|
||||||
@ -1,29 +1,29 @@
|
|||||||
# Stage 1: Build
|
# Stage 1: Build the frontend
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20 AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install --legacy-peer-deps
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN npm install
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Runtime (NGINX)
|
# Stage 2: Serve with nginx
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Install dos2unix to fix Windows line endings
|
# Install dos2unix
|
||||||
RUN apk add --no-cache dos2unix
|
RUN apk add --no-cache dos2unix
|
||||||
|
|
||||||
# Clean default nginx html
|
# Copy built app
|
||||||
RUN rm -rf /usr/share/nginx/html/*
|
|
||||||
|
|
||||||
# Copy built frontend
|
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy entrypoint and normalize line endings
|
# ✅ Copy env.js.template
|
||||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
COPY public/env.js.template /etc/env/env.js.template
|
||||||
RUN dos2unix /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh
|
|
||||||
|
|
||||||
# Fallback env.js (to avoid 404 before initContainer writes real one)
|
# ✅ Copy nginx config
|
||||||
RUN echo "window.env = {}" > /usr/share/nginx/html/env.js
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# Set entrypoint
|
# ✅ Add env generator script to nginx entrypoint hook
|
||||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
COPY 10-generate-env.sh /docker-entrypoint.d/10-generate-env.sh
|
||||||
|
RUN dos2unix /docker-entrypoint.d/10-generate-env.sh && chmod +x /docker-entrypoint.d/10-generate-env.sh
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Generate env.js at runtime from env var
|
|
||||||
cat <<EOF > /usr/share/nginx/html/env.js
|
|
||||||
window.env = {
|
|
||||||
VITE_API_URL: "${VITE_API_URL}"
|
|
||||||
};
|
|
||||||
EOF
|
|
||||||
|
|
||||||
exec nginx -g "daemon off;"
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
const API_BASE = window?.env?.VITE_API_URL || '/api';
|
const API_BASE = window?.ENV?.API_BASE || "";
|
||||||
|
|
||||||
export async function fetchSections() {
|
export async function fetchSections() {
|
||||||
const res = await fetch(`${API_BASE}/apps`);
|
const res = await fetch(`${API_BASE}/apps`);
|
||||||
|
|||||||
@ -1,6 +1,59 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// export default defineConfig({
|
||||||
|
// plugins: [react()],
|
||||||
|
// server: {
|
||||||
|
// proxy: {
|
||||||
|
// '/apps': 'http://localhost:8000',
|
||||||
|
// '/add_app': 'http://localhost:8000',
|
||||||
|
// '/icon': 'http://localhost:8000',
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// import { defineConfig } from 'vite';
|
||||||
|
// import react from '@vitejs/plugin-react';
|
||||||
|
|
||||||
|
// export default defineConfig({
|
||||||
|
// plugins: [react()],
|
||||||
|
// });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user