OPS-1: Dockerfiles (net10 API + nginx frontend) + production config
- GerbilManagerWebAPI/Dockerfile: net7->net10 multi-stage; build context=repo root (includes ServiceDefaults); port 8080 (.NET 10 container default) - gerbil-manager-web/Dockerfile: drop VITE_API_BASE_URL build-arg; nginx proxies /api/* to api:8080 (strip prefix), /scalar, /openapi/ -- one published port 80 - gerbil-manager-web/src/api/client.ts: default API_BASE_URL /api (relative), no hostname coupling at build time; Aspire still injects absolute LAN URL in dev - GerbilManagerWebAPI/Program.cs: run EF Migrate() at startup always (not Dev-only) - GerbilManager.ServiceDefaults/Extensions.cs: expose /health + /alive in all environments (compose healthcheck requires them in Production) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,25 +1,48 @@
|
||||
# Build-Stufe: Vite-Produktionsbuild
|
||||
# Build context: repo root (Dockerfile liest aus gerbil-manager-web/).
|
||||
# docker build -f gerbil-manager-web/Dockerfile -t gerbilmanager-frontend .
|
||||
#
|
||||
# Produktion: kein VITE_API_BASE_URL nötig — client.ts fällt auf '/api' zurück,
|
||||
# nginx proxyt /api/* transparent zum API-Container (keine Host-Kopplung zur Build-Zeit).
|
||||
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY gerbil-manager-web/package.json gerbil-manager-web/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY gerbil-manager-web/ .
|
||||
# Basis-URL der API (zur Build-Zeit eingebettet; Browser erreicht die API über den Host)
|
||||
ARG VITE_API_BASE_URL=http://localhost:80
|
||||
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
|
||||
RUN npm run build
|
||||
|
||||
# Laufzeit-Stufe: statische Auslieferung über nginx
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
# SPA-Fallback: alle Pfade auf index.html umleiten (react-router)
|
||||
|
||||
# nginx: SPA-Fallback + Reverse-Proxy für /api, /scalar, /openapi zum API-Container.
|
||||
RUN printf 'server {\n\
|
||||
listen 3000;\n\
|
||||
listen 80;\n\
|
||||
root /usr/share/nginx/html;\n\
|
||||
index index.html;\n\
|
||||
\n\
|
||||
# API-Aufrufe: /api/* -> API-Container /* (Praefix wird entfernt)\n\
|
||||
location /api/ {\n\
|
||||
proxy_pass http://api:8080/;\n\
|
||||
proxy_set_header Host $host;\n\
|
||||
proxy_set_header X-Real-IP $remote_addr;\n\
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
||||
}\n\
|
||||
\n\
|
||||
# Scalar API-Doku und OpenAPI-Spec direkt vom Backend\n\
|
||||
location /scalar {\n\
|
||||
proxy_pass http://api:8080/scalar;\n\
|
||||
proxy_set_header Host $host;\n\
|
||||
}\n\
|
||||
location /openapi/ {\n\
|
||||
proxy_pass http://api:8080/openapi/;\n\
|
||||
proxy_set_header Host $host;\n\
|
||||
}\n\
|
||||
\n\
|
||||
# SPA-Fallback: alle anderen Pfade laden index.html (React Router)\n\
|
||||
location / {\n\
|
||||
try_files $uri $uri/ /index.html;\n\
|
||||
}\n\
|
||||
}\n' > /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 3000
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
@@ -2,11 +2,12 @@ import { de } from '../strings/de'
|
||||
|
||||
/**
|
||||
* Basis-URL der GerbilManagerWebAPI.
|
||||
* Per VITE_API_BASE_URL konfigurierbar (z. B. in Docker / Aspire);
|
||||
* Standard ist das lokale Dev-Profil der API (launchSettings.json, Profil "http").
|
||||
* Dev (Aspire): VITE_API_BASE_URL wird von AppHost zur Laufzeit gesetzt (LAN-IP + Port).
|
||||
* Produktion (Docker/nginx): kein Env-Var nötig — nginx proxyt /api/* zum API-Container,
|
||||
* daher funktioniert der relative Pfad /api auf jedem Host ohne Build-Zeit-Kopplung.
|
||||
*/
|
||||
export const API_BASE_URL: string =
|
||||
import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:5179'
|
||||
import.meta.env.VITE_API_BASE_URL ?? '/api'
|
||||
|
||||
export class ApiError extends Error {
|
||||
readonly status: number | null
|
||||
|
||||
Reference in New Issue
Block a user