@sveltejs/kit 1.0.0-next.222 → 1.0.0-next.223
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/kit.js +22 -0
- package/dist/chunks/index.js +1 -0
- package/dist/chunks/index3.js +1 -0
- package/dist/cli.js +17 -2
- package/dist/ssr.js +22 -0
- package/package.json +1 -1
- package/types/config.d.ts +4 -0
- package/types/internal.d.ts +5 -0
package/assets/kit.js
CHANGED
|
@@ -1849,6 +1849,28 @@ async function respond(incoming, options, state = {}) {
|
|
|
1849
1849
|
locals: {}
|
|
1850
1850
|
};
|
|
1851
1851
|
|
|
1852
|
+
const { parameter, allowed } = options.method_override;
|
|
1853
|
+
const method_override = incoming.url.searchParams.get(parameter)?.toUpperCase();
|
|
1854
|
+
|
|
1855
|
+
if (method_override) {
|
|
1856
|
+
if (request.method.toUpperCase() === 'POST') {
|
|
1857
|
+
if (allowed.includes(method_override)) {
|
|
1858
|
+
request.method = method_override;
|
|
1859
|
+
} else {
|
|
1860
|
+
const verb = allowed.length === 0 ? 'enabled' : 'allowed';
|
|
1861
|
+
const body = `${parameter}=${method_override} is not ${verb}. See https://kit.svelte.dev/docs#configuration-methodoverride`;
|
|
1862
|
+
|
|
1863
|
+
return {
|
|
1864
|
+
status: 400,
|
|
1865
|
+
headers: {},
|
|
1866
|
+
body
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
throw new Error(`${parameter}=${method_override} is only allowed with POST requests`);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1852
1874
|
// TODO remove this for 1.0
|
|
1853
1875
|
/**
|
|
1854
1876
|
* @param {string} property
|
package/dist/chunks/index.js
CHANGED
|
@@ -225,6 +225,7 @@ async function create_plugin(config, output, cwd) {
|
|
|
225
225
|
hooks,
|
|
226
226
|
hydrate: config.kit.hydrate,
|
|
227
227
|
manifest,
|
|
228
|
+
method_override: config.kit.methodOverride,
|
|
228
229
|
paths: {
|
|
229
230
|
base: config.kit.paths.base,
|
|
230
231
|
assets: config.kit.paths.assets ? SVELTE_KIT_ASSETS : config.kit.paths.base
|
package/dist/chunks/index3.js
CHANGED
|
@@ -307,6 +307,7 @@ export class App {
|
|
|
307
307
|
hooks,
|
|
308
308
|
hydrate: ${s(config.kit.hydrate)},
|
|
309
309
|
manifest,
|
|
310
|
+
method_override: ${s(config.kit.methodOverride)},
|
|
310
311
|
paths: { base, assets },
|
|
311
312
|
prefix: assets + '/${config.kit.appDir}/',
|
|
312
313
|
prerender: ${config.kit.prerender.enabled},
|
package/dist/cli.js
CHANGED
|
@@ -479,6 +479,21 @@ const options = object(
|
|
|
479
479
|
|
|
480
480
|
hydrate: boolean(true),
|
|
481
481
|
|
|
482
|
+
methodOverride: object({
|
|
483
|
+
parameter: string('_method'),
|
|
484
|
+
allowed: validate([], (input, keypath) => {
|
|
485
|
+
if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
|
|
486
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (input.map((i) => i.toUpperCase()).includes('GET')) {
|
|
490
|
+
throw new Error(`${keypath} cannot contain "GET"`);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return input;
|
|
494
|
+
})
|
|
495
|
+
}),
|
|
496
|
+
|
|
482
497
|
package: object({
|
|
483
498
|
dir: string('package'),
|
|
484
499
|
// excludes all .d.ts and filename starting with _
|
|
@@ -853,7 +868,7 @@ async function launch(port, https) {
|
|
|
853
868
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
854
869
|
}
|
|
855
870
|
|
|
856
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
871
|
+
const prog = sade('svelte-kit').version('1.0.0-next.223');
|
|
857
872
|
|
|
858
873
|
prog
|
|
859
874
|
.command('dev')
|
|
@@ -1005,7 +1020,7 @@ async function check_port(port) {
|
|
|
1005
1020
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1006
1021
|
if (open) launch(port, https);
|
|
1007
1022
|
|
|
1008
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1023
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.223'}\n`));
|
|
1009
1024
|
|
|
1010
1025
|
const protocol = https ? 'https:' : 'http:';
|
|
1011
1026
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/dist/ssr.js
CHANGED
|
@@ -1779,6 +1779,28 @@ async function respond(incoming, options, state = {}) {
|
|
|
1779
1779
|
locals: {}
|
|
1780
1780
|
};
|
|
1781
1781
|
|
|
1782
|
+
const { parameter, allowed } = options.method_override;
|
|
1783
|
+
const method_override = incoming.url.searchParams.get(parameter)?.toUpperCase();
|
|
1784
|
+
|
|
1785
|
+
if (method_override) {
|
|
1786
|
+
if (request.method.toUpperCase() === 'POST') {
|
|
1787
|
+
if (allowed.includes(method_override)) {
|
|
1788
|
+
request.method = method_override;
|
|
1789
|
+
} else {
|
|
1790
|
+
const verb = allowed.length === 0 ? 'enabled' : 'allowed';
|
|
1791
|
+
const body = `${parameter}=${method_override} is not ${verb}. See https://kit.svelte.dev/docs#configuration-methodoverride`;
|
|
1792
|
+
|
|
1793
|
+
return {
|
|
1794
|
+
status: 400,
|
|
1795
|
+
headers: {},
|
|
1796
|
+
body
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
} else {
|
|
1800
|
+
throw new Error(`${parameter}=${method_override} is only allowed with POST requests`);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1782
1804
|
// TODO remove this for 1.0
|
|
1783
1805
|
/**
|
|
1784
1806
|
* @param {string} property
|
package/package.json
CHANGED
package/types/config.d.ts
CHANGED
package/types/internal.d.ts
CHANGED
|
@@ -131,6 +131,7 @@ export interface SSRRenderOptions {
|
|
|
131
131
|
hooks: Hooks;
|
|
132
132
|
hydrate: boolean;
|
|
133
133
|
manifest: SSRManifest;
|
|
134
|
+
method_override: MethodOverride;
|
|
134
135
|
paths: {
|
|
135
136
|
base: string;
|
|
136
137
|
assets: string;
|
|
@@ -230,3 +231,7 @@ export type NormalizedLoadOutput = Either<
|
|
|
230
231
|
>;
|
|
231
232
|
|
|
232
233
|
export type TrailingSlash = 'never' | 'always' | 'ignore';
|
|
234
|
+
export interface MethodOverride {
|
|
235
|
+
parameter: string;
|
|
236
|
+
allowed: string[];
|
|
237
|
+
}
|