-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
way to disable 404 route #1918
Comments
FWIW, you can work around it fairly easily by checking the const freshHandler = await createHandler(manifest, config);
Deno.serve(async (req, info) => {
const { pathname } = new URL(req.url);
if (pathname === "/special-route") {
return new Response('special route');
}
const res = await freshHandler(req, info);
if (res.status === 404) {
return new Response('overridden 404 response', { status: 404 });
}
return res;
}); Only drawback is that the Fresh 404 page is still rendered (i.e. slight performance hit, and any side effects from rendering it will still happen). |
Good idea! If the 404 page is empty, this shouldn't be too bad. Still, a way to opt out would be imo valuable. |
@harrysolovay @lionel-rowe, what's the expected behavior here? I've modified export interface RouterOptions {
trailingSlash?: boolean;
ignoreFilePattern?: RegExp;
disable404?: boolean;
} So you can now use this (at least in my branch on my computer) to disable the 404 page. But what does that mean exactly? Right now I have this diff somewhere within the server code: async renderNotFound<Data = undefined>(data: Data) {
+ if (disable404) {
+ throw new Deno.errors.NotFound();
+ }
return await renderNotFound(req, params, ctx, data);
}, So if the flag is true, instead of running the |
Yes.
This would be a fine solution, although returning undefined may be preferable imo. |
Follow-up from #1916
Might it be valuable to provide a way to disable the 404 route?
The text was updated successfully, but these errors were encountered: