Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(auth): print the banner's API Docs URL only when served
Yudhi Armyndharis748e3469c41d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d30d09949..99cd74e57 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -114,6 +114,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Reject poll votes with no matching options while preserving explicit vote clearing.- Read the duration of an outgoing Baileys audio file in a separate process and a voice note's waveform through ffmpeg, status voice notes included, so a crafted file can no longer abort or exhaust the gateway.- Bound `GET /api/search` to 1000 characters and 32 distinct words and run a repeated word once, so one request can no longer hold the event loop on SQLite for seconds.+- Print the startup banner's API Docs URL only when Swagger is served, so a production boot no longer points at a `404`.### Documentationdiff --git a/src/modules/auth/auth.service.spec.ts b/src/modules/auth/auth.service.spec.tsindex 969749634..a7a1c8dec 100644--- a/src/modules/auth/auth.service.spec.ts+++ b/src/modules/auth/auth.service.spec.ts@@ -1172,6 +1172,31 @@ describe('AuthService', () => {expect(bannerText()).toContain('(check dashboard for keys)');});+ // /api/docs answers 404 whenever Swagger is off, which is the default under NODE_ENV=production.+ it.each([+ ['off by default in production', { NODE_ENV: 'production' }, false],+ ['on in production when enabled', { NODE_ENV: 'production', ENABLE_SWAGGER: 'true' }, true],+ ['on by default outside production', { NODE_ENV: 'development' }, true],+ ['off outside production when disabled', { NODE_ENV: 'development', ENABLE_SWAGGER: 'false' }, false],+ ])('boot prints the API docs URL only when it is served: %s', async (_label, env, served) => {+ const saved = { NODE_ENV: process.env.NODE_ENV, ENABLE_SWAGGER: process.env.ENABLE_SWAGGER };+ delete process.env.ENABLE_SWAGGER;+ Object.assign(process.env, env);+ try {+ (repository.count as jest.Mock).mockResolvedValue(1);++ await service.onModuleInit();++ expect(bannerText()).toContain('Dashboard:');+ expect(bannerText().includes('/api/docs')).toBe(served);+ } finally {+ for (const [name, value] of Object.entries(saved)) {+ if (value === undefined) delete process.env[name];+ else process.env[name] = value;+ }+ }+ });+it('boot keeps a live bootstrap key: file untouched, banner shows the masked fingerprint', async () => {(repository.count as jest.Mock).mockResolvedValue(1);existsSpy.mockReturnValue(true);diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.tsindex bf3091528..1a91deb2d 100644--- a/src/modules/auth/auth.service.ts+++ b/src/modules/auth/auth.service.ts@@ -25,6 +25,7 @@ import { ActiveKeyIndex } from './active-key-index';import { apiKeyAuthorizationFingerprint, normalizeScopeList } from './api-key-authorization';import { normalizeChatAllowList } from '../../common/security/chat-scope';import { EventsGateway, type ApiKeyEvictionReason } from '../events/events.gateway';+import { isSwaggerEnabled } from '../../config/bootstrap-security';/*** A 401 that names no stored key: the credential was missing or matched no row. Producing one costs@@ -120,7 +121,10 @@ export class AuthService implements OnModuleInit, OnModuleDestroy {this.logger.log(' π’ Welcome to OpenWA - WhatsApp API Gateway');this.logger.log('');this.logger.log(` π Dashboard: ${dashboardUrl}`);- this.logger.log(` π API Docs: ${apiBaseUrl}/api/docs`);+ // Swagger is off by default under NODE_ENV=production, where the URL would answer 404.+ if (isSwaggerEnabled(process.env.ENABLE_SWAGGER, process.env.NODE_ENV)) {+ this.logger.log(` π API Docs: ${apiBaseUrl}/api/docs`);+ }this.logger.log('');if (isNewKey) {this.logger.log(' π API Key (newly created):');