Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep mis-cased /api paths out of the SPA handler

Yudhi Armyndharis2b68c5a175c2
diff --git a/src/configure-app.ts b/src/configure-app.ts
index efb54fa47..8c9f5deb4 100644
--- a/src/configure-app.ts
+++ b/src/configure-app.ts
@@ -121,14 +121,16 @@ export function configureApp(app: INestApplication, options: ConfigureAppOptions
if (dashboard.enabled && existsSync(join(dashboard.distDir, 'index.html'))) {
const dashboardIndex = readFileSync(join(dashboard.distDir, 'index.html'), 'utf8');
app.use((req: Request, res: Response, next: NextFunction) => {
+ // Lowercased because routing matches these prefixes case-insensitively.
+ const path = req.path.toLowerCase();
const excluded =
- req.path.startsWith('/api/') ||
- req.path === '/api' ||
- req.path.startsWith('/socket.io/') ||
- req.path === '/socket.io' ||
- req.path.startsWith('/mcp/') ||
- req.path === '/mcp' ||
- req.path.startsWith('/assets/');
+ path.startsWith('/api/') ||
+ path === '/api' ||
+ path.startsWith('/socket.io/') ||
+ path === '/socket.io' ||
+ path.startsWith('/mcp/') ||
+ path === '/mcp' ||
+ path.startsWith('/assets/');
const documentRequest =
req.method === 'GET' &&
!excluded &&
diff --git a/test/serve-static.e2e-spec.ts b/test/serve-static.e2e-spec.ts
index 0faabeb1a..fe0aaf2f4 100644
--- a/test/serve-static.e2e-spec.ts
+++ b/test/serve-static.e2e-spec.ts
@@ -158,6 +158,12 @@ describe.each([
expect(res.body).toEqual({ ok: true });
});
+ it('lets Nest handle a mis-cased /api route, as routing matches it case-insensitively', async () => {
+ const res = await request(app.getHttpServer()).get('/API/ping');
+ expect(res.status).toBe(200);
+ expect(res.body).toEqual({ ok: true });
+ });
+
it('returns a JSON 404 (not the SPA) for unknown /api routes', async () => {
const res = await request(app.getHttpServer()).get('/api/does-not-exist');
expect(res.status).toBe(404);