# Use Node.js Slim (Debian-based) for better-sqlite3 native addon support
FROM node:24-slim

# Install build dependencies for native addons
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy package files
COPY source/package*.json ./

# Install dependencies
RUN npm install --production

# Copy application files (excluding node_modules via .dockerignore)
COPY source/js ./js
COPY source/public ./public

# Create data directory
RUN mkdir -p data

# Create logs directory
RUN mkdir -p logs

# Expose port (default 5050, can be overridden with PORT env variable)
EXPOSE 5050

# Set environment variable defaults
ENV NODE_ENV=production \
    PORT=5050

# Run the server
CMD ["node", "js/server.js"]
