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:
46
src/admin/server.js
Normal file
46
src/admin/server.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import logger from '../utils/logger.js';
|
||||
import { requireAuth, handleLogin, handleLogout, renderLogin } from './auth.js';
|
||||
import dashboardRouter from './routes/dashboard.js';
|
||||
import usersRouter from './routes/users.js';
|
||||
import productsRouter from './routes/products.js';
|
||||
import walletsRouter from './routes/wallets.js';
|
||||
import purchasesRouter from './routes/purchases.js';
|
||||
import auditRouter from './routes/audit.js';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const app = express();
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use('/admin/style.css', express.static(join(__dirname, 'public', 'style.css')));
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok', uptime: process.uptime() });
|
||||
});
|
||||
|
||||
app.get('/login', (req, res) => {
|
||||
res.send(renderLogin());
|
||||
});
|
||||
|
||||
app.post('/login', handleLogin);
|
||||
app.get('/logout', handleLogout);
|
||||
|
||||
app.use(requireAuth);
|
||||
|
||||
app.use('/', dashboardRouter);
|
||||
app.use('/users', usersRouter);
|
||||
app.use('/products', productsRouter);
|
||||
app.use('/wallets', walletsRouter);
|
||||
app.use('/purchases', purchasesRouter);
|
||||
app.use('/audit', auditRouter);
|
||||
|
||||
export function startAdminPanel() {
|
||||
const port = parseInt(process.env.ADMIN_PORT || '3001', 10);
|
||||
app.listen(port, () => {
|
||||
logger.info({ port }, 'Admin panel started');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user