From 37d701a1217a51adeeaa08f890c03320fa7b748d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 5 May 2021 09:01:39 +0200 Subject: [PATCH] fix: reload of admin/api page yields 404 fixes: #836 --- src/lib/app.ts | 4 ++-- src/server-dev.ts | 1 + src/test/e2e/routes/routes.test.ts | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/app.ts b/src/lib/app.ts index d4c7a94c40..470072d71e 100644 --- a/src/lib/app.ts +++ b/src/lib/app.ts @@ -127,8 +127,8 @@ export default function getApp( }); app.get(`${baseUriPath}/*`, (req, res) => { - if (req.path.includes('api')) { - res.status(404).send(); + if (req.path.startsWith(`${baseUriPath}/api`)) { + res.status(404).send({ message: '404 - Not found' }); return; } diff --git a/src/server-dev.ts b/src/server-dev.ts index e5b5734871..29d1ed870c 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -16,6 +16,7 @@ unleash.start( }, server: { enableRequestLogger: true, + baseUriPath: '', }, logLevel: LogLevel.debug, enableOAS: true, diff --git a/src/test/e2e/routes/routes.test.ts b/src/test/e2e/routes/routes.test.ts index c170e8953c..b0e65fb3f4 100644 --- a/src/test/e2e/routes/routes.test.ts +++ b/src/test/e2e/routes/routes.test.ts @@ -27,7 +27,16 @@ test('hitting a baseUri path returns HTML document', async t => { test('hitting an api path that does not exist returns 404', async t => { t.plan(0); const request = await setupAppWithBaseUrl(stores); - await request.get('/hosted/api/i-dont-exist').expect(404); + await request.get('/api/i-dont-exist').expect(404); +}); + +test('hitting an /admin/api returns HTML document', async t => { + t.plan(0); + const request = await setupAppWithBaseUrl(stores); + await request + .get('/admin/api') + .expect(200) + .expect('Content-Type', 'text/html; charset=utf-8'); }); test('hitting a non-api returns HTML document', async t => {