FROM node:24-trixie-slim AS build

WORKDIR /app-new

COPY app-new/backend/package*.json backend/
COPY app-new/frontend/package*.json frontend/
RUN cd backend && npm install
RUN cd frontend && npm install

COPY app-new .

RUN cd backend && npm run build
RUN cd frontend && npm run build

FROM node:24-trixie-slim AS runtime

WORKDIR /app-new
ENV NODE_ENV=production
ENV PORT=3000

COPY app-new/backend/package*.json backend/
RUN cd backend && npm install --omit=dev

COPY --from=build /app-new/dist dist
COPY --from=build /app-new/templates templates
COPY --from=build /app-new/templates.json templates.json
COPY entrypoint.sh entrypoint.sh
RUN chmod +x entrypoint.sh

EXPOSE 3000
CMD ["./entrypoint.sh"]
