From 8f1120a35275e2f46f368c16c76b99721e34d20c Mon Sep 17 00:00:00 2001 From: William Killerud Date: Mon, 25 Nov 2024 14:18:44 +0100 Subject: [PATCH] fix: don't set content-type text/html for manifest route --- lib/podlet.js | 7 ++++++- tests/podlet.test.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/podlet.js b/lib/podlet.js index 1e79ebf8..bae9f729 100644 --- a/lib/podlet.js +++ b/lib/podlet.js @@ -996,7 +996,12 @@ export default class PodiumPodlet { objobj.set('locals.podium', incoming, res); res.header('podlet-version', this.version); - res.header('content-type', 'text/html'); + if ( + req.path == this.contentRoute || + req.path == this.fallbackRoute + ) { + res.header('content-type', 'text/html'); + } res.sendHeaders = () => { res.write(''); diff --git a/tests/podlet.test.js b/tests/podlet.test.js index 3b6a37c3..53a7babb 100644 --- a/tests/podlet.test.js +++ b/tests/podlet.test.js @@ -112,6 +112,10 @@ class FakeExpressServer { } if (onFallbackRoute) this.app.get(podlet.fallback({ prefix: true }), onFallbackRoute); + this.app.get(podlet.manifest(), (req, res) => { + const manifest = JSON.parse(JSON.stringify(podlet)); + res.status(200).json(manifest); + }); this.app.use( onRequest || ((req, res) => { @@ -1272,6 +1276,24 @@ tap.test('res.podiumSend() - should set content-type text/html', async (t) => { await server.close(); }); +tap.test( + 'manifest.json - should set content-type application/json', + async (t) => { + const podlet = new Podlet(DEFAULT_OPTIONS); + const server = new FakeExpressServer(podlet); + + await server.listen(); + const result = await server.get({ raw: true, path: podlet.manifest() }); + + t.ok(JSON.parse(result.response)); + t.equal( + result.headers['content-type'], + 'application/json; charset=utf-8', + ); + await server.close(); + }, +); + // ############################################# // .defaults() // #############################################