Closed mastermakrela closed 3 weeks ago
I Think sk_fetch
is causing the problem
you should do this instead
export const GET: RequestHandler = async ({ fetch , url, platform }) => {
It works for me
@Rishab49 sk_fetch
is just a rename, the code above is equivalent to
export const GET = async (event) => {
const sk_fetch = event.fetch;
...
}
I renamed it to clearly differentiate global fetch and the one from SvelteKit here
It works for me
Did you test it with Cloudflare adapter & wrangler? If yes, could you share a minimal setup? That would really help me.
oh I forgot to test it with wrangler(apologies), its a bug
Describe the bug
According to the documentation (here and here), kits
fetch
should be able to handle relative paths on the server.This works in development, but not in production (I've tested Cloudflare and node adapters).
If I do this:
The response is always this exact 404 (as far as I can tell): https://github.com/sveltejs/kit/blob/df6641a701f8155d7023ab6a5b17ef39df31d730/packages/kit/src/runtime/server/respond.js#L118-L120
We end up here, because the
server_fetch
doesn't recognise this path as an asset. Following check seams to be the problem:https://github.com/sveltejs/kit/blob/df6641a701f8155d7023ab6a5b17ef39df31d730/packages/kit/src/runtime/server/fetch.js#L84-L87
as it doesn't check
manifest._.server_assets
I've created an exhaustive reproduction that shows differences between sk/global fetch and absolute/relative path here: https://github.com/mastermakrela/sveltekit-relative-assets-fetch-bug
Solutions considered
Use
read
read
is sync and Cloudflaresenv.ASSETS.fetch
isn'tChange
is_asset
check in Kit toChange
is_static_asset
check in Cloudflare adapter to:Use global fetch
Semantically async
read
+ Cloudflare implementation, would be most satisfying, but it's probably leas viable, because of breaking change.But independent of read, not being able to fetch assets using relative path on server seams to be a bug, that should be fixed (or if not at least a warning in dev mode would be nice).
Reproduction
https://github.com/mastermakrela/sveltekit-relative-assets-fetch-bug
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response