feat: Add full PDPA compliance with cookie consent, admin dashboard, and conditional analytics

Features implemented:
 Cookie consent banner (Accept/Reject) with localStorage storage
 Conditional Umami Analytics (loads only with consent)
 Admin dashboard at /admin/consent-logs (password protected)
 API endpoints for consent logging (POST/GET/DELETE)
 Astro DB integration with consent logging schema
 Production-ready Dockerfile with Node.js server adapter
 Node.js 20+ requirement for Astro 5.x compatibility

Files added:
- src/components/consent/CookieBanner.astro
- src/pages/api/consent/index.ts (POST/GET endpoints)
- src/pages/api/consent/[sessionId]/index.ts (DELETE endpoint)
- src/pages/admin/consent-logs.astro (admin dashboard)
- db/schema.ts (ConsentLog table schema)

Files modified:
- src/layouts/Layout.astro (CookieBanner + conditional Umami)
- astro.config.mjs (Node adapter + DB integration)
- package.json (start script, engines field, dependencies)
- Dockerfile (custom deployment with Node.js server)

Configuration:
- Umami Analytics: Conditional loading based on consent
- Admin password: 'changeme' (MUST change in production)
- Database: SQLite file (data/consent.db)
- Server: Node.js standalone adapter

Deployment:
- Docker build with SQLite runtime support
- Custom Dockerfile for Easypanel
- Start command: node dist/server/entry.mjs

Security notes:
⚠️  CHANGE ADMIN_PASSWORD before production deployment
⚠️  Enable HTTPS for secure cookie consent
⚠️  Consider server-side authentication for admin dashboard
This commit is contained in:
Kunthawat Greethong
2026-03-10 21:25:49 +07:00
parent c6b56b9e26
commit b485320afc
10 changed files with 1473 additions and 20 deletions

View File

@@ -3,12 +3,23 @@ WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN mkdir -p ./data && ASTRO_DB_REMOTE_URL=file:./data/consent.db npx astro build --remote
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
RUN npm install --production
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/db ./db
COPY --from=builder /app/data ./data
RUN apk add --no-cache sqlite-libs
EXPOSE 80
CMD ["npx", "serve", "dist", "-l", "80"]
ENV NODE_ENV=production
ENV ASTRO_DB_REMOTE_URL=file:/app/data/consent.db
ENV HOST=0.0.0.0
ENV PORT=80
CMD ["node", "dist/server/entry.mjs"]