FROM node:18-slim

# Install dependencies for Puppeteer
# Using 'chromium' from Debian repos ensures support for AMD64, ARM64, and ARMv7
RUN apt-get update \
  && apt-get install -y chromium \
  fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 python3 make g++ \
  --no-install-recommends \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY package*.json ./

# Install dependencies
RUN npm install

COPY . .

# Environment variable to tell Puppeteer to skip downloading Chromium
# and use the installed system chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium

EXPOSE 3000

CMD ["node", "index.js"]
