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
When using a rest endpoint built with kit like the following structure
/api/post/index.js
/api/post/[id].js
in order to catch routes like
/api/post
/api/post/1
and building with the static adapter, only the first one will be generated, while the ones with the same prefix won't.
In the config, the order of pages (config.kit.prerender.entries) changes the behaviour.
That is, if /api/post is set first, at build time, a file /build/api/post will be generated throwing an error when accessing /build/api/post/1.
Conversely, if /api/post/1 come first in the list of pages, at build time the file /build/api/post/1 will be generated and an error will be thrown when accessing /api/post.
If multiple /api/post/11 pages are specified before /api/page in the config, then they will all be generated (i.e. pages for all posts), but the one without id will be missing and throw the error.
Okey, so that's what I found out after some digging the source code:
Both /api/post and /api/post/[id] are prerendered at build time, but if /api/post already exists and is a file, it is not possible to create a directory post and to populate it. Conversly, if /api/post/[id] exist, then it is not possible to create a file named /api/post, since a directory is a special kind of file under linux (which, I guess, is the most used OS for kit on the server side).
This leaves the open question of how to statically generate files for an endpoint.
A possible solution could be to add index.json during prerendering on every request to an endpoint, or let every prerendered endpoint end with .json in the file name.
Describe the bug
When using a rest endpoint built with kit like the following structure
in order to catch routes like
and building with the static adapter, only the first one will be generated, while the ones with the same prefix won't.
In the config, the order of pages (
config.kit.prerender.entries
) changes the behaviour.That is, if
/api/post
is set first, at build time, a file/build/api/post
will be generated throwing an error when accessing/build/api/post/1
.Conversely, if
/api/post/1
come first in the list of pages, at build time the file/build/api/post/1
will be generated and an error will be thrown when accessing/api/post
.If multiple
/api/post/11
pages are specified before/api/page
in theconfig
, then they will all be generated (i.e. pages for all posts), but the one withoutid
will be missing and throw the error.Reproduction
Here's the demo app showing the problem
https://github.com/lsabi/my-app
Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
I believe, that the static adapter only checks for the existence of either file or folder, but does not distinguish between the two.
Will try to dig into during my free time if needed.
The text was updated successfully, but these errors were encountered: