# --- Frontend: TanStack Start (SSR, Node runtime) ---
FROM node:22-alpine AS build
WORKDIR /app
# VITE_API_URL must be present at build time: Vite inlines it into the bundle.
ARG VITE_API_URL
ENV VITE_API_URL=${VITE_API_URL}
COPY package.json package-lock.json* ./
RUN npm ci || npm install
COPY . .
RUN npm run build

FROM node:22-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
# TanStack Start (Vite) emits a self-contained server bundle in .output.
COPY --from=build /app/.output ./.output
EXPOSE 3000
CMD ["node", ".output/server/index.mjs"]
