FROM node:22.23.4

# Instalar Bun dentro del contenedor
RUN curl -fsSL https://bun.sh/install | bash \
    && ln -s /root/.bun/bin/bun /usr/local/bin/bun

WORKDIR /app

# Copiamos package.json y package-lock.json
COPY package*.json ./

# 1. Instalar dependencias usando npm con legacy deps
RUN npm install --legacy-peer-deps

# 2. Instalar dependencias también con bun (si tienes bun.lockb)
RUN bun install || true

# Copiar todo el proyecto
COPY . .

# 3. Compilar Angular SSR
# Este comando DEBE existir en package.json
RUN npm run build

EXPOSE 4000

# 4. Ejecutar el servidor SSR real de Angular
# En tu Dockerfile, cambia el CMD a:
CMD ["node", "--max-old-space-size=4096", "--no-warnings", "dist/marketplace/server/server.mjs"]
