chore(deployment): add docker-compose and nginx setup for production

- Added Dockerfile and nginx.conf for frontend production build.
- Added docker-compose.yml to orchestrate backend and frontend.
- Updated geminiService.ts to support relative API paths via Nginx proxy.
- Updated documentation with deployment instructions for Synology/Docker.
This commit is contained in:
2025-12-22 16:14:08 +00:00
parent 461d9d3bbc
commit ba5ed0516b
5 changed files with 133 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
# Stage 1: Build the React App
FROM node:18-alpine as build
WORKDIR /app
# Copy package files first for better caching
COPY package.json package-lock.json ./
RUN npm install
# Copy source code
COPY . .
# Build for production
RUN npm run build
# Stage 2: Serve with Nginx
FROM nginx:alpine
# Copy built assets from Stage 1
COPY --from=build /app/dist /usr/share/nginx/html
# Copy custom Nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,22 @@
server {
listen 80;
# 1. Serve React Frontend (Static Files)
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html; # Support for React Router (SPA)
}
# 2. Proxy API Requests to Backend Container
location /api/ {
# 'backend' is the service name in docker-compose.yml
# Port 3001 is where the Node.js bridge listens
proxy_pass http://backend:3001/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

View File

@@ -3,8 +3,12 @@ import { LeadStatus, AnalysisResult, Competitor, Language, Tier, EmailDraft, Sea
// const apiKey = process.env.API_KEY; // Nicht mehr direkt im Frontend verwendet
// const ai = new GoogleGenAI({ apiKey: apiKey || '' }); // Nicht mehr direkt im Frontend verwendet
// URL unserer lokalen Node.js API-Brücke
const API_BASE_URL = `http://${window.location.hostname}:3001/api`;
// URL Konfiguration:
// Im Production-Build (Docker/Nginx) nutzen wir den relativen Pfad '/api', da Nginx als Reverse Proxy fungiert.
// Im Development-Modus (lokal) greifen wir direkt auf den Port 3001 zu.
const API_BASE_URL = import.meta.env.PROD
? '/api'
: `http://${window.location.hostname}:3001/api`;
// Helper to extract JSON (kann ggf. entfernt werden, wenn das Backend immer sauberes JSON liefert)
const extractJson = (text: string): any => {