Some checks failed
Deploy to Production / Deploy to Server (push) Failing after 20s
- Add pino structured logging with request IDs (X-Request-Id header) - Add 30s timeout to acquirePage() and renderPdf/renderUrlPdf - Add verification cache cleanup (every 15min) and rate limit cleanup (every 60s) - Read version from package.json in health endpoint - Add compression middleware - Escape currency in templates (XSS fix) - Add static asset caching (1h maxAge) - Remove deprecated docker-compose version field - Replace all console.log/error with pino logger
59 lines
No EOL
1.7 KiB
TypeScript
59 lines
No EOL
1.7 KiB
TypeScript
import { Router } from "express";
|
|
import { createRequire } from "module";
|
|
import { getPoolStats } from "../services/browser.js";
|
|
import { pool } from "../services/db.js";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const { version: APP_VERSION } = require("../../package.json");
|
|
|
|
export const healthRouter = Router();
|
|
|
|
healthRouter.get("/", async (_req, res) => {
|
|
const poolStats = getPoolStats();
|
|
let databaseStatus: any;
|
|
let overallStatus = "ok";
|
|
let httpStatus = 200;
|
|
|
|
// Check database connectivity
|
|
try {
|
|
const client = await pool.connect();
|
|
try {
|
|
const result = await client.query('SELECT version()');
|
|
const version = result.rows[0]?.version || 'Unknown';
|
|
// Extract just the PostgreSQL version number (e.g., "PostgreSQL 15.4")
|
|
const versionMatch = version.match(/PostgreSQL ([\d.]+)/);
|
|
const shortVersion = versionMatch ? `PostgreSQL ${versionMatch[1]}` : 'PostgreSQL';
|
|
|
|
databaseStatus = {
|
|
status: "ok",
|
|
version: shortVersion
|
|
};
|
|
} finally {
|
|
client.release();
|
|
}
|
|
} catch (error: any) {
|
|
databaseStatus = {
|
|
status: "error",
|
|
message: error.message || "Database connection failed"
|
|
};
|
|
overallStatus = "degraded";
|
|
httpStatus = 503;
|
|
}
|
|
|
|
const response = {
|
|
status: overallStatus,
|
|
version: APP_VERSION,
|
|
database: databaseStatus,
|
|
pool: {
|
|
size: poolStats.poolSize,
|
|
active: poolStats.totalPages - poolStats.availablePages,
|
|
available: poolStats.availablePages,
|
|
queueDepth: poolStats.queueDepth,
|
|
pdfCount: poolStats.pdfCount,
|
|
restarting: poolStats.restarting,
|
|
uptimeSeconds: Math.round(poolStats.uptimeMs / 1000),
|
|
},
|
|
};
|
|
|
|
res.status(httpStatus).json(response);
|
|
}); |