# ================================
# Build Stage
# ================================
FROM node:20-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy source code
COPY . .

# Build the application
RUN npm run build

# ================================
# Production Stage
# ================================
FROM node:20-alpine AS production

# Set working directory
WORKDIR /app

# Set environment to production
ENV NODE_ENV=production

# Copy package files for preview command
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.nuxt ./.nuxt
COPY --from=builder /app/.output ./.output

# Expose port
EXPOSE 3001

# Set default environment variables
ENV HOST=0.0.0.0
ENV PORT=3001
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3001

# Start the application using preview command
CMD ["npm", "run", "preview"]
