Skip to content

Commit

Permalink
allow /favicon.ico to be a valid route (#5046)
Browse files Browse the repository at this point in the history
* allow /favicon.ico to be a valid route - closes #4968

* Update packages/kit/src/runtime/server/index.js

* Update .changeset/young-flies-camp.md

Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com>

Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com>
  • Loading branch information
Rich-Harris and mrkishi committed May 24, 2022
1 parent d8609f7 commit 21ee694
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-flies-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] stop suppressing `/favicon.ico` requests, handle them as a valid route
2 changes: 0 additions & 2 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ export async function create_plugin(config) {
}
}

if (req.url === '/favicon.ico') return not_found(res);

if (!decoded.startsWith(config.kit.paths.base)) {
return not_found(res, `Not found (did you mean ${config.kit.paths.base + req.url}?)`);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/test/apps/basics/src/routes/favicon.ico.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function get() {
return {
body: {
surprise: 'lol'
}
};
}
Binary file removed packages/kit/test/apps/basics/static/favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,14 @@ test.describe.parallel('Routing', () => {
await page.goto('/static');
expect(await page.textContent('h1')).toBe('hello');
});

test('/favicon.ico is a valid route', async ({ request }) => {
const response = await request.get('/favicon.ico');
expect(response.status()).toBe(200);

const data = await response.json();
expect(data).toEqual({ surprise: 'lol' });
});
});

test.describe.parallel('Session', () => {
Expand Down

0 comments on commit 21ee694

Please sign in to comment.