Skip to content

Commit 2145088

Browse files
committed
simplify ENDPOINT_METHODS and PAGE_METHODS stuff
1 parent fc8a03d commit 2145088

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

packages/kit/src/constants.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
66

77
export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';
88

9-
export const ENDPOINT_METHODS = new Set([
10-
'GET',
11-
'POST',
12-
'PUT',
13-
'PATCH',
14-
'DELETE',
15-
'OPTIONS',
16-
'HEAD'
17-
]);
9+
export const ENDPOINT_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
1810

19-
export const PAGE_METHODS = new Set(['GET', 'POST', 'HEAD']);
11+
export const PAGE_METHODS = ['GET', 'POST', 'HEAD'];

packages/kit/src/core/postbuild/analyse.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,13 @@ async function analyse({ manifest_path, env }) {
9393
prerender = mod.prerender;
9494
}
9595

96-
Object.keys(mod).forEach((key) => {
97-
const method = /** @type {import('types').HttpMethod} */ (key);
98-
if (mod[method] && ENDPOINT_METHODS.has(method)) {
99-
api_methods.push(method);
100-
} else if (mod.fallback && key === 'fallback') {
101-
api_methods.push('*');
102-
}
103-
});
96+
for (const method of /** @type {import('types').HttpMethod[]} */ (ENDPOINT_METHODS)) {
97+
if (mod[method]) api_methods.push(method);
98+
}
99+
100+
if (mod.fallback) {
101+
api_methods.push('*');
102+
}
104103

105104
config = mod.config;
106105
entries = mod.entries;

packages/kit/src/runtime/server/endpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function is_endpoint_request(event) {
8181
const { method, headers } = event.request;
8282

8383
// These methods exist exclusively for endpoints
84-
if (ENDPOINT_METHODS.has(method) && !PAGE_METHODS.has(method)) {
84+
if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) {
8585
return true;
8686
}
8787

packages/kit/src/runtime/server/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function method_not_allowed(mod, method) {
3535

3636
/** @param {Partial<Record<import('types').HttpMethod, any>>} mod */
3737
export function allowed_methods(mod) {
38-
const allowed = Array.from(ENDPOINT_METHODS).filter((method) => method in mod);
38+
const allowed = ENDPOINT_METHODS.filter((method) => method in mod);
3939

4040
if ('GET' in mod || 'HEAD' in mod) allowed.push('HEAD');
4141

0 commit comments

Comments
 (0)