-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: add server endpoint fallback
handler
#9755
Conversation
🦋 Changeset detectedLatest commit: 0ac4a79 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Have we thought about the effects this might have on https://kit.svelte.dev/docs/routing#server-content-negotiation ? I haven't thought about that all the way through yet. Also, if we decided (as in #9780) to start adding |
Content negotiation is still in play here, so the
I'm not sure myself. Will need to start reading the MDN docs on what |
After reading MDN, it seems we would only need to return
|
@s3812497 it looks like this PR will need a rebase |
d262fbd
to
b0c5e63
Compare
all is still misleading or ambiguous. If you have |
I think it's probably fine, esp since the way people would learn about it is via docs which can explain it - however there could still be better words out there for it? |
Other name suggestions were:
|
Name suggestion: |
I like fallback more for your description. |
Why not just support this? /** @type {import('@sveltejs/kit').[Handle](https://kit.svelte.dev/docs/types#public-types-handle)} */
export async function handle({ event, resolve }) {
if (event.url.pathname.startsWith('/custom')) {
return new Response('custom response');
}
const response = await resolve(event);
return response;
} |
all
handlerfallback
handler
Handling this case in the |
The export |
Right, no my suggestion was to allow Another benefit would be scenarios where you have a common resolution you want to do once up front for a whole routing scope, almost like what you get with layouts in view routes. |
Sorry, I misunderstood. I'd definitely be in favour of subdirectory handle hooks replacing this as also mentioned by Ben |
Ah I missed that earlier comment. I also don't see any replies to it. Is there some other location that subdirectory hooks has/is being discussed? |
Honestly after thinking about it a bit I think there's certainly room for both a |
There doesn't seem to be from what I've seen (probably just talked about internally?). You may open an issue for it. |
Astro 3.0 is moving to capitalized function names too. I forwarded some feedback from here and they may rename the |
Can this be... merged? |
I'm still not sure if we should go ahead with this if we're planning to implement per directory |
fallback is different from hooks as it would only be called if no other handler is defined. hooks would always be called. so i think both can make sense even if you could be able to implement fallback with a hook, it may be complicated to figure out which handlers are defined. |
closes #9164
Adds a catch-all handler that handles all unimplemented valid server requests. This is done by exporting the
fallback
function from a+server.js
file.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.