You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the +server.js, When trying to do a fetch call to the endpoint "/api/posts", I get a 404 response when using "event.fetch" and then a crash:
functiongetFeedItems(fetch){returnfetchPosts(fetch).then(data=>{console.log(data);// JSON parse error, because i received a 404 html response});}exportasyncfunctionGET(event){getFeedItems(event.fetch);returnnewResponse(`...`.trim(),{headers: {'Content-Type': 'application/xml'}});}
I've tested calling this endpoint from a +page.server.js, and the data is retrieved as expected. But not using event.fetch in a +server.js (also tested using fetch in place of event in the exported GET)
Reproduction
git clone https://github.com/rsousacode/AspNetSPA_SvelteKit && cd AspNetSPA_SvelteKit && git checkout maybe-bug
Run dotnet run (it'll run the whole thing)
In the menu, click on "Not working" and check routes/not-working to see the code
Error: Not found: /api/posts
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:391:13)
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:232:5)
at #options.hooks.handle (/node_modules/@sveltejs/kit/src/runtime/server/index.js:42:55)
at Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:229:40)
at async fetch (/node_modules/@sveltejs/kit/src/runtime/server/fetch.js:134:16)
at async eval (/node_modules/@sveltejs/kit/src/runtime/server/fetch.js:27:10)
undefined:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token <in JSON at position 0
The possible workaround is to use the full non-proxied path of the service when developing. After finishing the tests, change to relative path again and expect it to work in production (where the proxy does it's job like it does in calls in +page.server.js), I'll change the severity when I have this assumption tested.
rsousacode
changed the title
+server.js - fetch call: Error: Not found: (but works on +page.server.js)
+server.js - fetch call: Error: Not found (but works on +page.server.js)
Feb 2, 2023
Describe the bug
I am trying to implement a RSS feed similarly to what the docs explain for doing a sitemap (https://kit.svelte.dev/docs/seo#manual-setup-sitemaps).
In the +server.js, When trying to do a fetch call to the endpoint "/api/posts", I get a 404 response when using "event.fetch" and then a crash:
I've tested calling this endpoint from a +page.server.js, and the data is retrieved as expected. But not using
event.fetch
in a +server.js (also tested using fetch in place of event in the exported GET)Reproduction
git clone https://github.com/rsousacode/AspNetSPA_SvelteKit && cd AspNetSPA_SvelteKit && git checkout maybe-bug
dotnet run
(it'll run the whole thing)Reproduction github repo: https://github.com/rsousacode/AspNetSPA_SvelteKit/tree/maybe-bug
Logs
System Info
Severity
blocking an upgrade
Additional Information
No response
The text was updated successfully, but these errors were encountered: