# 1. Build Stage
FROM node:20-alpine AS build

WORKDIR /app

# Copy dependency files
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy source code
COPY . .

# Build with node-server preset (not cloudflare-module)
RUN NITRO_PRESET=node-server npm run build

# 2. Production Stage
FROM node:20-alpine

WORKDIR /app

# Copy built output from build stage
COPY --from=build /app/.output ./.output

EXPOSE 3000

ENV PORT=3000
ENV HOST=0.0.0.0

CMD ["node", ".output/server/index.mjs"]
