feat: web admin panel + better-sqlite3 migration + Docker fixes

- Added Express.js admin panel on port 3001 (ADMIN_PORT env)
  - Dashboard: stats (users, products, purchases, revenue)
  - Users: list, details, ban/unban toggle
  - Products: CRUD by category
  - Wallets: list with balances
  - Purchases: history with filters
  - Audit log: view audit trail
  - Auth: token-based login with ADMIN_SECRET env var
- Migrated sqlite3 → better-sqlite3
  - database.js: async adapter (runAsync/allAsync/getAsync)
  - purchaseService.js: lastID → lastInsertRowid
  - userService.js: lastID → lastInsertRowid
  - Removed sqlite3 from package.json
- Fixed: dotenv/config import added to index.js
- Fixed: ENCRYPTION_KEY validation (32+ char hex)
- Fixed: Dockerfile multi-stage build (no python needed)
- Fixed: Docker DNS (network: host in build)
- Fixed: docker-compose port 3001, healthcheck on 3001
- Added express, cookie-parser, pino-pretty, better-sqlite3 deps
This commit is contained in:
NW
2026-06-22 10:54:01 +01:00
parent 25d8507b11
commit 4657b1dfb5
24 changed files with 1619 additions and 931 deletions

View File

@@ -2,9 +2,6 @@ FROM node:22-alpine AS builder
WORKDIR /app
# Install build dependencies for native modules (sqlite3, better-sqlite3)
RUN apk add --no-cache python3 make g++
COPY package*.json ./
RUN npm install && npm cache clean --force
@@ -12,20 +9,20 @@ RUN npm install && npm cache clean --force
FROM node:22-alpine
# Install runtime dependencies
# WireGuard needs community repo on some alpine versions
RUN apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community \
wireguard-tools \
RUN apk update && \
apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community \
wireguard-tools \
&& apk add --no-cache \
iptables \
iproute2 \
openresolv \
bash \
curl \
iptables \
iproute2 \
openresolv \
bash \
curl \
&& rm -rf /var/cache/apk/*
WORKDIR /app
# Copy node_modules from builder (with native addons pre-compiled)
# Copy node_modules from builder
COPY --from=builder /app/node_modules ./node_modules
COPY package*.json ./
@@ -41,7 +38,6 @@ RUN mkdir -p /app/db
# Health check: bot responds to /health on port 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -sf http://localhost:3000/health || exit 1
CMD curl -sf http://localhost:3001/health || exit 1
# start.sh runs as root (needed for wg-quick), then drops to node
CMD ["/bin/bash", "/app/start.sh"]