Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(bootstrap): log the startup banner through the structured logger
Yudhi Armyndharisc926f4dd892f
diff --git a/src/configure-app.ts b/src/configure-app.tsindex de7d36b84..efb54fa47 100644--- a/src/configure-app.ts+++ b/src/configure-app.ts@@ -13,6 +13,7 @@ import {} from './config/inflight-body-budget';import { ActiveKeyIndex } from './modules/auth/active-key-index';import { requestContextMiddleware } from './common/middleware/request-context.middleware';+import { createLogger } from './common/services/logger.service';import { injectDashboardCspNonce } from './config/dashboard-csp';import { resolveCorsPolicy, isUpgradeInsecureRequestsEnabled, resolveBodyLimit } from './config/bootstrap-security';import { resolveRequestTimeoutMs } from './config/http-timeouts';@@ -142,8 +143,8 @@ export function configureApp(app: INestApplication, options: ConfigureAppOptions// CORS Configuration (#221 hardening)const corsPolicy = resolveCorsPolicy(process.env.CORS_ORIGINS, process.env.NODE_ENV);if (process.env.NODE_ENV === 'production' && corsPolicy.origins.length === 0 && !corsPolicy.allowAnyOrigin) {- console.warn(- '[Bootstrap] No explicit CORS_ORIGINS in production (wildcard "*" is refused): cross-origin browser ' ++ createLogger('Bootstrap').warn(+ 'No explicit CORS_ORIGINS in production (wildcard "*" is refused): cross-origin browser ' +'requests will be blocked. Set CORS_ORIGINS to your dashboard origin(s).',);}diff --git a/src/main-logging.spec.ts b/src/main-logging.spec.tsnew file mode 100644index 000000000..066631f16--- /dev/null+++ b/src/main-logging.spec.ts@@ -0,0 +1,15 @@+import { readFileSync } from 'fs';+import { resolve } from 'path';++/**+ * main.ts boots on import, so its banner and advisories cannot be exercised by a unit test; lock the+ * source instead, the way load-env.spec.ts locks its import order. A raw console line bypasses+ * LOG_LEVEL and, in production, lands as plain text in an otherwise JSON log stream.+ */+describe('bootstrap logging', () => {+ it.each(['main.ts', 'configure-app.ts'])('%s writes through the structured logger, not console', file => {+ const source = readFileSync(resolve(__dirname, file), 'utf8');++ expect(source).not.toMatch(/\bconsole\.\w+\(/);+ });+});diff --git a/src/main.ts b/src/main.tsindex 371b2dcde..b557bd258 100644--- a/src/main.ts+++ b/src/main.ts@@ -241,20 +241,20 @@ async function bootstrap() {// sending #731 chasing BASE_URL/BIND_HOST/API_PORT instead of the real cause.const publicUrl = process.env.BASE_URL || `http://localhost:${port}`;- console.log(`🚀 OpenWA is running on: ${publicUrl}`);+ bootstrapLogger.log(`OpenWA is running on: ${publicUrl}`);if (swaggerEnabled) {- console.log(`📚 Swagger docs: ${publicUrl}/api/docs`);+ bootstrapLogger.log(`Swagger docs: ${publicUrl}/api/docs`);}// Make the dashboard-serving outcome explicit so a missing build (no UI on `/`)// is obvious instead of a silent 404.if (!dashboardServingEnabled) {- console.log('🖥️ Dashboard: serving disabled (SERVE_DASHBOARD=false); API only');+ bootstrapLogger.log('Dashboard: serving disabled (SERVE_DASHBOARD=false); API only');} else if (dashboardBuildPresent) {- console.log(`🖥️ Dashboard: serving bundled UI at ${publicUrl}`);+ bootstrapLogger.log(`Dashboard: serving bundled UI at ${publicUrl}`);} else {- console.warn(- `⚠️ Dashboard: no build at ${DASHBOARD_DIST} - UI disabled (API still serves /api). ` ++ bootstrapLogger.warn(+ `Dashboard: no build at ${DASHBOARD_DIST} - UI disabled (API still serves /api). ` +'Run `npm run build:all` to bundle it, or use the Vite dev server (`npm run dev`).',);}@@ -270,8 +270,8 @@ async function bootstrap() {dashboardServed: dashboardServingEnabled && dashboardBuildPresent,})) {- console.warn(- '⚠️ Dashboard: CSP upgrade-insecure-requests is ON (production default). If this instance is ' ++ bootstrapLogger.warn(+ 'Dashboard: CSP upgrade-insecure-requests is ON (production default). If this instance is ' +"reached over plain HTTP, the browser will upgrade the UI's scripts to https:// and the " +'dashboard will render blank. Behind a TLS proxy? Ignore this. Serving direct HTTP? Set ' +'CSP_UPGRADE_INSECURE_REQUESTS=false.',