Skip to content
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

Prerendering with +server.js blocks cURL requests #10102

Closed
dextermb opened this issue Jun 6, 2023 · 5 comments
Closed

Prerendering with +server.js blocks cURL requests #10102

dextermb opened this issue Jun 6, 2023 · 5 comments
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@dextermb
Copy link

dextermb commented Jun 6, 2023

Describe the bug

When attempting to cURL a preview build of SvelteKit that uses prerender within a +server.js file a 405 Method not allowed is returned. However when providing an extra "Accept" header 200 OK is returned, and when using +page.server.js instead a 200 OK is returned.

Example repository linked below.

Reproduction

https://github.com/dextermb/svelte-kit-prerender-405-server-js

Logs

No response

System Info

npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
Need to install the following packages:
  envinfo@7.8.1
Ok to proceed? (y) y

  System:
    OS: macOS 13.4
    CPU: (12) arm64 Apple M2 Max
    Memory: 79.95 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
    npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Firefox: 110.0.1
    Safari: 16.5

Severity

annoyance

Additional Information

No response

@antony antony added the bug Something isn't working label Jun 6, 2023
@elliott-with-the-longest-name-on-github
Copy link
Contributor

I think you may have forgotten a commit in your repro -- there's no +server file that I could find.

@dextermb
Copy link
Author

dextermb commented Jun 9, 2023

I think you may have forgotten a commit in your repro -- there's no +server file that I could find.

Hey, it's part of the set up steps [see the README.md]. Just simply run:

echo 'export const prerender = true' > 'src/routes/+server.js'

@elliott-with-the-longest-name-on-github
Copy link
Contributor

Ahhh, okay, yeah -- I don't believe this is a bug. There are two things at play here:

  1. You can't prerender +server files with mutative methods (POST, for example) -- this doesn't apply here, but does apply to the above PR
    • @gtm-nayan In light of this, I'm not sure if your PR is necessary -- it certainly shouldn't be for prerendering, though if it fixes some undiscovered bug for runtime code, we might still want to merge it
  2. You can't prerender a route with both a +server file and a +page file. This is because content negotiation is impossible for prerendered files -- there's no server logic to disambiguate a request to /foo using the Accept header
    • I think you're seeing mixed success here right now because the preview server is still performing this content negotiation for you when it shouldn't be?

This PR will throw an error when you try to do this: https://github.com/sveltejs/kit/pull/9994/files

@antony antony added documentation Improvements or additions to documentation and removed bug Something isn't working labels Jun 12, 2023
@antony
Copy link
Member

antony commented Jun 12, 2023

This makes sense now I read it. I wonder if there's a way we can better document / make this obvious. I feel like adding actual documentation around it might cause confusion when this is very much a niche issue.

It's unfortunate that preview isn't working as-per vercel, but I'm not sure what we can do about this - Vercel does some magic hosting pre-rendered files directly on the edge, whereas I assume the node adapter would not, so perhaps we have to put this down to adapter specifics and accept that preview will always behave a bit more like the node adapter than anything else.

@dummdidumm
Copy link
Member

Closed via #11256, having conflicting route definitions / both a +page.js and +server.js when prerendering is an error in SvelteKit 2.0

@dummdidumm dummdidumm added this to the 2.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
4 participants