ARG NGINX_VERSION

# --- Stage 1: Build the Client (TypeScript -> JS) ---
FROM node:18-slim AS client-builder
WORKDIR /usr/opt/pythonapp

# Wir brauchen die Projekt-Dateien
COPY Client/ ./Client/
COPY App_Server/ ./App_Server/
COPY NGINX_Server/ ./NGINX_Server/

# Abhängigkeiten installieren und bauen
WORKDIR /usr/opt/pythonapp/Client
RUN npm install
RUN npx tsc && npx rollup -c

# --- Stage 2: NGINX Server (Final Image) ---
FROM nginx:${NGINX_VERSION}

RUN ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
RUN mkdir /etc/certs

# Statischen HTML-Ordner inklusive des frischen JS aus Stage 1 kopieren
COPY --from=client-builder /usr/opt/pythonapp/NGINX_Server/html /usr/share/nginx/html
