# Kino frontend — React build + nginx reverse proxy
# Multi-stage: build with Node, serve with nginx

# ---------- Build stage ----------
FROM node:20-alpine AS build

WORKDIR /app

# When BACKEND_URL is empty, frontend uses relative /api which nginx below proxies.
# This keeps auth cookies / CORS trivial and works behind any reverse proxy.
ENV REACT_APP_BACKEND_URL=""

COPY package.json yarn.lock* ./
RUN yarn install --frozen-lockfile --network-timeout 600000

COPY . .
RUN yarn build

# ---------- Serve stage ----------
FROM nginx:1.27-alpine

# Custom config: SPA fallback + /api reverse proxy + large uploads + streaming timeouts
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Static build
COPY --from=build /app/build /usr/share/nginx/html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
