Skip to content

Commit

Permalink
fix: don't set content-type text/html for manifest route
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Nov 25, 2024
1 parent 42cabfb commit 8f1120a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
22 changes: 22 additions & 0 deletions tests/podlet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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()
// #############################################
Expand Down

0 comments on commit 8f1120a

Please sign in to comment.