# Development only. Not for production use.
FROM node:24-slim

# slim carries no trust store and workerd reads the system one
RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates \
  && rm -rf /var/lib/apt/lists/*

COPY <<'EOF' /usr/local/bin/avatar-entrypoint.sh
#!/bin/sh
set -eu
if [ -f /caddy-ca/root.crt ]; then
  cp /caddy-ca/root.crt /usr/local/share/ca-certificates/caddy-dev.crt
  update-ca-certificates >/dev/null
fi
npm ci --no-audit --no-fund
exec npx wrangler dev --ip 0.0.0.0 --port 8787 \
  --var "AVATAR_SHARED_SECRET:${AVATAR_SHARED_SECRET}" \
  --var "PLC_DIRECTORY_URL:${PLC_DIRECTORY_URL}"
EOF
RUN chmod +x /usr/local/bin/avatar-entrypoint.sh

WORKDIR /src

EXPOSE 8787

ENTRYPOINT ["/usr/local/bin/avatar-entrypoint.sh"]
