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

fix: correctly analyse exported endpoint methods during build #11019

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-deers-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: correctly analyse exported server API methods during build
5 changes: 3 additions & 2 deletions packages/kit/src/core/postbuild/analyse.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ async function analyse({ manifest_path, env }) {
prerender = mod.prerender;
}

Object.values(mod).forEach((/** @type {import('types').HttpMethod} */ method) => {
Object.keys(mod).forEach((key) => {
const method = /** @type {import('types').HttpMethod} */ (key);
if (mod[method] && ENDPOINT_METHODS.has(method)) {
api_methods.push(method);
} else if (mod.fallback) {
} else if (mod.fallback && key === 'fallback') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this would be equivalent and shorter?

Suggested change
} else if (mod.fallback && key === 'fallback') {
} else if (key === 'fallback') {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends if we want to check the value of fallback for truthiness. Is there a case (or is it even possible) where someone conditionally assigns a request handler to it?
e.g., export const fallback = dev ? requestHandler : undefined;

api_methods.push('*');
}
});
Expand Down
Loading