# Dockerfile.react — Multi-stage build for Modern.js SSR standalone app.
# Coexists with the legacy ASP.NET Dockerfile.

FROM node:24-slim AS deps
WORKDIR /app

RUN corepack enable pnpm

COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

FROM deps AS build
WORKDIR /app

COPY modern.config.ts module-federation.config.ts tsconfig.json ./
COPY src/ src/
# Modern.js publicDir: fonts, images, leaflet marker icons, favicons.
# Copied into dist/standalone/public/ at build time. Without this the
# /assets/** URLs resolve to the SPA index HTML (OTS font-parse failures,
# broken backgrounds, missing tile icons).
COPY config/ config/

RUN pnpm build:standalone

FROM node:24-slim AS runtime
WORKDIR /app

ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=8080

RUN corepack enable pnpm

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist/standalone/ ./dist/standalone/
COPY --from=build /app/src/ ./src/
COPY package.json modern.config.ts module-federation.config.ts ./

EXPOSE 8080

CMD ["pnpm", "exec", "modern", "serve"]
