@sveltejs/kit 1.0.12 → 1.1.0
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/package.json +1 -1
- package/src/core/adapt/builder.js +1 -1
- package/src/core/{prerender → postbuild}/crawl.js +0 -0
- package/src/core/{prerender → postbuild}/entities.js +0 -0
- package/src/core/{prerender → postbuild}/fallback.js +10 -7
- package/src/core/postbuild/index.js +106 -0
- package/src/core/{prerender → postbuild}/prerender.js +32 -106
- package/src/core/{prerender → postbuild}/queue.js +0 -0
- package/src/core/sync/sync.js +10 -0
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +89 -0
- package/src/core/sync/write_tsconfig.js +10 -1
- package/src/core/utils.js +0 -9
- package/src/exports/vite/build/build_server.js +11 -163
- package/src/exports/vite/build/build_service_worker.js +3 -2
- package/src/exports/vite/build/utils.js +1 -0
- package/src/exports/vite/dev/index.js +72 -114
- package/src/exports/vite/index.js +81 -28
- package/src/exports/vite/preview/index.js +11 -12
- package/src/runtime/app/environment.js +1 -1
- package/src/runtime/app/forms.js +5 -1
- package/src/runtime/app/paths.js +1 -1
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/start.js +1 -2
- package/src/runtime/client/utils.js +1 -2
- package/src/runtime/control.js +23 -5
- package/src/runtime/server/ambient.d.ts +8 -0
- package/src/runtime/server/cookie.js +4 -5
- package/src/runtime/server/data/index.js +3 -2
- package/src/runtime/server/endpoint.js +5 -5
- package/src/runtime/server/fetch.js +11 -9
- package/src/runtime/server/index.js +54 -395
- package/src/runtime/server/page/csp.js +9 -11
- package/src/runtime/server/page/index.js +13 -8
- package/src/runtime/server/page/load_data.js +2 -3
- package/src/runtime/server/page/render.js +26 -19
- package/src/runtime/server/page/respond_with_error.js +20 -13
- package/src/runtime/server/page/types.d.ts +0 -1
- package/src/runtime/server/respond.js +419 -0
- package/src/runtime/server/utils.js +21 -4
- package/src/runtime/shared.js +28 -0
- package/types/ambient.d.ts +7 -29
- package/types/internal.d.ts +23 -37
- package/src/runtime/env.js +0 -12
- package/src/runtime/paths.js +0 -11
|
@@ -12,7 +12,7 @@ import { SVELTE_KIT_ASSETS } from '../../constants.js';
|
|
|
12
12
|
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
13
13
|
import * as sync from '../../core/sync/sync.js';
|
|
14
14
|
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
15
|
-
import { runtime_base, runtime_directory,
|
|
15
|
+
import { runtime_base, runtime_directory, logger } from '../../core/utils.js';
|
|
16
16
|
import { load_config } from '../../core/config/index.js';
|
|
17
17
|
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
18
18
|
import { build_server } from './build/build_server.js';
|
|
@@ -64,15 +64,69 @@ const enforced_config = {
|
|
|
64
64
|
root: true
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
const options_regex = /(export\s+const\s+(prerender|csr|ssr|trailingSlash))\s*=/s;
|
|
68
|
+
|
|
69
|
+
/** @type {Set<string>} */
|
|
70
|
+
const warned = new Set();
|
|
71
|
+
|
|
72
|
+
/** @type {import('@sveltejs/vite-plugin-svelte').PreprocessorGroup} */
|
|
73
|
+
const warning_preprocessor = {
|
|
74
|
+
script: ({ content, filename }) => {
|
|
75
|
+
if (!filename) return;
|
|
76
|
+
|
|
77
|
+
const basename = path.basename(filename);
|
|
78
|
+
if (basename.startsWith('+page.') || basename.startsWith('+layout.')) {
|
|
79
|
+
const match = content.match(options_regex);
|
|
80
|
+
if (match) {
|
|
81
|
+
const fixed = basename.replace('.svelte', '(.server).js/ts');
|
|
82
|
+
|
|
83
|
+
const message =
|
|
84
|
+
`\n${colors.bold().red(path.relative('.', filename))}\n` +
|
|
85
|
+
`\`${match[1]}\` will be ignored — move it to ${fixed} instead. See https://kit.svelte.dev/docs/page-options for more information.`;
|
|
86
|
+
|
|
87
|
+
if (!warned.has(message)) {
|
|
88
|
+
console.log(message);
|
|
89
|
+
warned.add(message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
markup: ({ content, filename }) => {
|
|
95
|
+
if (!filename) return;
|
|
96
|
+
|
|
97
|
+
const basename = path.basename(filename);
|
|
98
|
+
if (basename.startsWith('+layout.') && !content.includes('<slot')) {
|
|
99
|
+
const message =
|
|
100
|
+
`\n${colors.bold().red(path.relative('.', filename))}\n` +
|
|
101
|
+
`\`<slot />\` missing — inner content will not be rendered`;
|
|
102
|
+
|
|
103
|
+
if (!warned.has(message)) {
|
|
104
|
+
console.log(message);
|
|
105
|
+
warned.add(message);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
67
111
|
/** @return {Promise<import('vite').Plugin[]>} */
|
|
68
112
|
export async function sveltekit() {
|
|
69
113
|
const svelte_config = await load_config();
|
|
70
114
|
|
|
115
|
+
/** @type {import('@sveltejs/vite-plugin-svelte').Options['preprocess']} */
|
|
116
|
+
let preprocess = svelte_config.preprocess;
|
|
117
|
+
if (Array.isArray(preprocess)) {
|
|
118
|
+
preprocess = [...preprocess, warning_preprocessor];
|
|
119
|
+
} else if (preprocess) {
|
|
120
|
+
preprocess = [preprocess, warning_preprocessor];
|
|
121
|
+
} else {
|
|
122
|
+
preprocess = warning_preprocessor;
|
|
123
|
+
}
|
|
124
|
+
|
|
71
125
|
/** @type {import('@sveltejs/vite-plugin-svelte').Options} */
|
|
72
126
|
const vite_plugin_svelte_options = {
|
|
73
127
|
configFile: false,
|
|
74
128
|
extensions: svelte_config.extensions,
|
|
75
|
-
preprocess
|
|
129
|
+
preprocess,
|
|
76
130
|
onwarn: svelte_config.onwarn,
|
|
77
131
|
compilerOptions: {
|
|
78
132
|
// @ts-expect-error SvelteKit requires hydratable true by default
|
|
@@ -128,7 +182,6 @@ function kit({ svelte_config }) {
|
|
|
128
182
|
|
|
129
183
|
/**
|
|
130
184
|
* @type {{
|
|
131
|
-
* build_dir: string;
|
|
132
185
|
* output_dir: string;
|
|
133
186
|
* client_out_dir: string;
|
|
134
187
|
* }}
|
|
@@ -147,7 +200,7 @@ function kit({ svelte_config }) {
|
|
|
147
200
|
|
|
148
201
|
manifest_data.nodes.forEach((node) => {
|
|
149
202
|
if (node.component) {
|
|
150
|
-
const resolved = path.resolve(
|
|
203
|
+
const resolved = path.resolve(node.component);
|
|
151
204
|
const relative = decodeURIComponent(
|
|
152
205
|
path.relative(svelte_config.kit.files.routes, resolved)
|
|
153
206
|
);
|
|
@@ -159,7 +212,7 @@ function kit({ svelte_config }) {
|
|
|
159
212
|
}
|
|
160
213
|
|
|
161
214
|
if (node.universal) {
|
|
162
|
-
const resolved = path.resolve(
|
|
215
|
+
const resolved = path.resolve(node.universal);
|
|
163
216
|
const relative = decodeURIComponent(
|
|
164
217
|
path.relative(svelte_config.kit.files.routes, resolved)
|
|
165
218
|
);
|
|
@@ -189,7 +242,7 @@ function kit({ svelte_config }) {
|
|
|
189
242
|
fs.readFileSync(`${paths.client_out_dir}/${vite_config.build.manifest}`, 'utf-8')
|
|
190
243
|
);
|
|
191
244
|
|
|
192
|
-
const entry_id = posixify(path.relative(
|
|
245
|
+
const entry_id = posixify(path.relative('.', `${runtime_directory}/client/start.js`));
|
|
193
246
|
|
|
194
247
|
return {
|
|
195
248
|
assets,
|
|
@@ -218,7 +271,6 @@ function kit({ svelte_config }) {
|
|
|
218
271
|
is_build = config_env.command === 'build';
|
|
219
272
|
|
|
220
273
|
paths = {
|
|
221
|
-
build_dir: `${svelte_config.kit.outDir}/build`,
|
|
222
274
|
output_dir: `${svelte_config.kit.outDir}/output`,
|
|
223
275
|
client_out_dir: `${svelte_config.kit.outDir}/output/client`
|
|
224
276
|
};
|
|
@@ -238,8 +290,8 @@ function kit({ svelte_config }) {
|
|
|
238
290
|
svelte_config.kit.files.lib,
|
|
239
291
|
svelte_config.kit.files.routes,
|
|
240
292
|
svelte_config.kit.outDir,
|
|
241
|
-
path.resolve(
|
|
242
|
-
path.resolve(
|
|
293
|
+
path.resolve('src'), // TODO this isn't correct if user changed all his files to sth else than src (like in test/options)
|
|
294
|
+
path.resolve('node_modules'),
|
|
243
295
|
path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
|
|
244
296
|
]);
|
|
245
297
|
// We can only add directories to the allow list, so we find out
|
|
@@ -254,6 +306,7 @@ function kit({ svelte_config }) {
|
|
|
254
306
|
const result = {
|
|
255
307
|
define: {
|
|
256
308
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
309
|
+
__SVELTEKIT_DEV__: config_env.command === 'serve',
|
|
257
310
|
__SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
|
|
258
311
|
},
|
|
259
312
|
resolve: {
|
|
@@ -276,7 +329,7 @@ function kit({ svelte_config }) {
|
|
|
276
329
|
// a linked dependency, and that causes modules to be imported twice
|
|
277
330
|
// under different IDs, which breaks a bunch of stuff
|
|
278
331
|
// https://github.com/vitejs/vite/pull/9296
|
|
279
|
-
external: ['@sveltejs/kit']
|
|
332
|
+
external: ['@sveltejs/kit', 'cookie', 'set-cookie-parser']
|
|
280
333
|
},
|
|
281
334
|
optimizeDeps: {
|
|
282
335
|
exclude: [
|
|
@@ -307,7 +360,7 @@ function kit({ svelte_config }) {
|
|
|
307
360
|
if (
|
|
308
361
|
is_illegal(id, {
|
|
309
362
|
cwd: normalized_cwd,
|
|
310
|
-
node_modules: vite.normalizePath(path.
|
|
363
|
+
node_modules: vite.normalizePath(path.resolve('node_modules')),
|
|
311
364
|
server: vite.normalizePath(path.join(normalized_lib, 'server'))
|
|
312
365
|
})
|
|
313
366
|
) {
|
|
@@ -358,10 +411,8 @@ function kit({ svelte_config }) {
|
|
|
358
411
|
|
|
359
412
|
if (is_build) {
|
|
360
413
|
if (!vite_config.build.watch) {
|
|
361
|
-
rimraf(paths.build_dir);
|
|
362
414
|
rimraf(paths.output_dir);
|
|
363
415
|
}
|
|
364
|
-
mkdirp(paths.build_dir);
|
|
365
416
|
mkdirp(paths.output_dir);
|
|
366
417
|
}
|
|
367
418
|
},
|
|
@@ -380,18 +431,18 @@ function kit({ svelte_config }) {
|
|
|
380
431
|
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
381
432
|
*/
|
|
382
433
|
async configureServer(vite) {
|
|
383
|
-
|
|
384
|
-
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
385
|
-
svelte_config.kit.version.name
|
|
386
|
-
);
|
|
434
|
+
const { set_paths, set_version } = await vite.ssrLoadModule(`${runtime_base}/shared.js`);
|
|
387
435
|
|
|
388
436
|
// set `import { base, assets } from '$app/paths'`
|
|
389
437
|
const { base, assets } = svelte_config.kit.paths;
|
|
390
438
|
|
|
391
|
-
|
|
439
|
+
set_paths({
|
|
392
440
|
base,
|
|
393
441
|
assets: assets ? SVELTE_KIT_ASSETS : base
|
|
394
442
|
});
|
|
443
|
+
|
|
444
|
+
// set `import { version } from '$app/environment'`
|
|
445
|
+
set_version(svelte_config.kit.version.name);
|
|
395
446
|
}
|
|
396
447
|
};
|
|
397
448
|
|
|
@@ -489,18 +540,17 @@ function kit({ svelte_config }) {
|
|
|
489
540
|
log.info('Building server');
|
|
490
541
|
|
|
491
542
|
const options = {
|
|
492
|
-
cwd,
|
|
493
543
|
config: svelte_config,
|
|
494
544
|
vite_config,
|
|
495
545
|
vite_config_env,
|
|
496
|
-
build_dir: paths.build_dir, // TODO just pass `paths`
|
|
497
546
|
manifest_data,
|
|
498
|
-
output_dir: paths.output_dir
|
|
499
|
-
service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker)
|
|
547
|
+
output_dir: paths.output_dir
|
|
500
548
|
};
|
|
501
549
|
const client = client_build_info(assets, chunks);
|
|
502
550
|
const server = await build_server(options, client);
|
|
503
551
|
|
|
552
|
+
const service_worker_entry_file = resolve_entry(svelte_config.kit.files.serviceWorker);
|
|
553
|
+
|
|
504
554
|
/** @type {import('types').BuildData} */
|
|
505
555
|
build_data = {
|
|
506
556
|
app_dir: svelte_config.kit.appDir,
|
|
@@ -508,7 +558,7 @@ function kit({ svelte_config }) {
|
|
|
508
558
|
svelte_config.kit.paths.base ? '/' : ''
|
|
509
559
|
}${svelte_config.kit.appDir}`,
|
|
510
560
|
manifest_data,
|
|
511
|
-
service_worker:
|
|
561
|
+
service_worker: !!service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
512
562
|
client,
|
|
513
563
|
server
|
|
514
564
|
};
|
|
@@ -528,9 +578,7 @@ function kit({ svelte_config }) {
|
|
|
528
578
|
const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
|
|
529
579
|
|
|
530
580
|
// do prerendering in a subprocess so any dangling stuff gets killed upon completion
|
|
531
|
-
const script = fileURLToPath(
|
|
532
|
-
new URL('../../core/prerender/prerender.js', import.meta.url)
|
|
533
|
-
);
|
|
581
|
+
const script = fileURLToPath(new URL('../../core/postbuild/index.js', import.meta.url));
|
|
534
582
|
|
|
535
583
|
const child = fork(
|
|
536
584
|
script,
|
|
@@ -575,14 +623,19 @@ function kit({ svelte_config }) {
|
|
|
575
623
|
})};\n`
|
|
576
624
|
);
|
|
577
625
|
|
|
578
|
-
if (
|
|
626
|
+
if (service_worker_entry_file) {
|
|
579
627
|
if (svelte_config.kit.paths.assets) {
|
|
580
628
|
throw new Error('Cannot use service worker alongside config.kit.paths.assets');
|
|
581
629
|
}
|
|
582
630
|
|
|
583
631
|
log.info('Building service worker');
|
|
584
632
|
|
|
585
|
-
await build_service_worker(
|
|
633
|
+
await build_service_worker(
|
|
634
|
+
options,
|
|
635
|
+
service_worker_entry_file,
|
|
636
|
+
prerendered,
|
|
637
|
+
client.vite_manifest
|
|
638
|
+
);
|
|
586
639
|
}
|
|
587
640
|
|
|
588
641
|
console.log(
|
|
@@ -34,19 +34,17 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
34
34
|
|
|
35
35
|
const etag = `"${Date.now()}"`;
|
|
36
36
|
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const dir = join(svelte_config.kit.outDir, 'output/server');
|
|
38
|
+
|
|
39
|
+
/** @type {import('types').ServerInternalModule} */
|
|
40
|
+
const { set_paths } = await import(pathToFileURL(join(dir, 'internal.js')).href);
|
|
39
41
|
|
|
40
42
|
/** @type {import('types').ServerModule} */
|
|
41
|
-
const { Server
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
building: false,
|
|
47
|
-
protocol,
|
|
48
|
-
read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
|
|
49
|
-
});
|
|
43
|
+
const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
|
|
44
|
+
|
|
45
|
+
const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
|
|
46
|
+
|
|
47
|
+
set_paths({ base, assets });
|
|
50
48
|
|
|
51
49
|
const server = new Server(manifest);
|
|
52
50
|
await server.init({
|
|
@@ -150,7 +148,8 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
150
148
|
const { remoteAddress } = req.socket;
|
|
151
149
|
if (remoteAddress) return remoteAddress;
|
|
152
150
|
throw new Error('Could not determine clientAddress');
|
|
153
|
-
}
|
|
151
|
+
},
|
|
152
|
+
read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
|
|
154
153
|
})
|
|
155
154
|
);
|
|
156
155
|
});
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -26,7 +26,11 @@ export function deserialize(result) {
|
|
|
26
26
|
|
|
27
27
|
/** @type {import('$app/forms').enhance} */
|
|
28
28
|
export function enhance(form, submit = () => {}) {
|
|
29
|
-
if (
|
|
29
|
+
if (
|
|
30
|
+
DEV &&
|
|
31
|
+
/** @type {HTMLFormElement} */ (HTMLFormElement.prototype.cloneNode.call(form)).method !==
|
|
32
|
+
'post'
|
|
33
|
+
) {
|
|
30
34
|
throw new Error('use:enhance can only be used on <form> fields with method="POST"');
|
|
31
35
|
}
|
|
32
36
|
|
package/src/runtime/app/paths.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { base, assets } from '../
|
|
1
|
+
export { base, assets } from '../shared.js';
|
|
@@ -915,7 +915,7 @@ export function create_client({ target, base }) {
|
|
|
915
915
|
/** @type {import('types').ServerDataNode | null} */
|
|
916
916
|
let server_data_node = null;
|
|
917
917
|
|
|
918
|
-
if (node.
|
|
918
|
+
if (node.has_server_load) {
|
|
919
919
|
// TODO post-https://github.com/sveltejs/kit/discussions/6124 we can use
|
|
920
920
|
// existing root layout data
|
|
921
921
|
try {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
2
|
import { create_client } from './client.js';
|
|
3
3
|
import { init } from './singletons.js';
|
|
4
|
-
import { set_paths } from '../
|
|
4
|
+
import { set_paths, set_version } from '../shared.js';
|
|
5
5
|
import { set_public_env } from '../env-public.js';
|
|
6
|
-
import { set_version } from '../env.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @param {{
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BROWSER, DEV } from 'esm-env';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
|
-
import { assets } from '../
|
|
4
|
-
import { version } from '../env.js';
|
|
3
|
+
import { assets, version } from '../shared.js';
|
|
5
4
|
import { PRELOAD_PRIORITIES } from './constants.js';
|
|
6
5
|
|
|
7
6
|
/* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
package/src/runtime/control.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class HttpError {
|
|
1
|
+
export let HttpError = class HttpError {
|
|
2
2
|
/**
|
|
3
3
|
* @param {number} status
|
|
4
4
|
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
@@ -17,9 +17,9 @@ export class HttpError {
|
|
|
17
17
|
toString() {
|
|
18
18
|
return JSON.stringify(this.body);
|
|
19
19
|
}
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
export class Redirect {
|
|
22
|
+
export let Redirect = class Redirect {
|
|
23
23
|
/**
|
|
24
24
|
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
25
25
|
* @param {string} location
|
|
@@ -28,12 +28,12 @@ export class Redirect {
|
|
|
28
28
|
this.status = status;
|
|
29
29
|
this.location = location;
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* @template {Record<string, unknown> | undefined} [T=undefined]
|
|
35
35
|
*/
|
|
36
|
-
export class ActionFailure {
|
|
36
|
+
export let ActionFailure = class ActionFailure {
|
|
37
37
|
/**
|
|
38
38
|
* @param {number} status
|
|
39
39
|
* @param {T} [data]
|
|
@@ -42,4 +42,22 @@ export class ActionFailure {
|
|
|
42
42
|
this.status = status;
|
|
43
43
|
this.data = data;
|
|
44
44
|
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* This is a grotesque hack that, in dev, allows us to replace the implementations
|
|
49
|
+
* of these classes that you'd get by importing them from `@sveltejs/kit` with the
|
|
50
|
+
* ones that are imported via Vite and loaded internally, so that instanceof
|
|
51
|
+
* checks work even though SvelteKit imports this module via Vite and consumers
|
|
52
|
+
* import it via Node
|
|
53
|
+
* @param {{
|
|
54
|
+
* ActionFailure: typeof ActionFailure;
|
|
55
|
+
* HttpError: typeof HttpError;
|
|
56
|
+
* Redirect: typeof Redirect;
|
|
57
|
+
* }} implementations
|
|
58
|
+
*/
|
|
59
|
+
export function replace_implementations(implementations) {
|
|
60
|
+
ActionFailure = implementations.ActionFailure;
|
|
61
|
+
HttpError = implementations.HttpError;
|
|
62
|
+
Redirect = implementations.Redirect;
|
|
45
63
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare module '__GENERATED__/server-internal.js' {
|
|
2
|
+
export const options: import('types').SSROptions;
|
|
3
|
+
export const get_hooks: () => Promise<{
|
|
4
|
+
handle?: import('types').Handle;
|
|
5
|
+
handleError?: import('types').HandleServerError;
|
|
6
|
+
handleFetch?: import('types').HandleFetch;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
@@ -11,10 +11,9 @@ const cookie_paths = {};
|
|
|
11
11
|
/**
|
|
12
12
|
* @param {Request} request
|
|
13
13
|
* @param {URL} url
|
|
14
|
-
* @param {boolean} dev
|
|
15
14
|
* @param {import('types').TrailingSlash} trailing_slash
|
|
16
15
|
*/
|
|
17
|
-
export function get_cookies(request, url,
|
|
16
|
+
export function get_cookies(request, url, trailing_slash) {
|
|
18
17
|
const header = request.headers.get('cookie') ?? '';
|
|
19
18
|
const initial_cookies = parse(header, { decode: (value) => value });
|
|
20
19
|
|
|
@@ -22,7 +21,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
22
21
|
// Emulate browser-behavior: if the cookie is set at '/foo/bar', its path is '/foo'
|
|
23
22
|
const default_path = normalized_url.split('/').slice(0, -1).join('/') || '/';
|
|
24
23
|
|
|
25
|
-
if (
|
|
24
|
+
if (__SVELTEKIT_DEV__) {
|
|
26
25
|
// TODO this could theoretically be wrong if the cookie was set unencoded?
|
|
27
26
|
const initial_decoded_cookies = parse(header, { decode: decodeURIComponent });
|
|
28
27
|
// Remove all cookies that no longer exist according to the request
|
|
@@ -77,7 +76,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
77
76
|
const req_cookies = parse(header, { decode: decoder });
|
|
78
77
|
const cookie = req_cookies[name]; // the decoded string or undefined
|
|
79
78
|
|
|
80
|
-
if (!
|
|
79
|
+
if (!__SVELTEKIT_DEV__ || cookie) {
|
|
81
80
|
return cookie;
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -111,7 +110,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
|
|
|
111
110
|
}
|
|
112
111
|
};
|
|
113
112
|
|
|
114
|
-
if (
|
|
113
|
+
if (__SVELTEKIT_DEV__) {
|
|
115
114
|
cookie_paths[name] = cookie_paths[name] ?? new Set();
|
|
116
115
|
if (!value) {
|
|
117
116
|
if (!cookie_paths[name].has(path) && cookie_paths[name].size > 0) {
|
|
@@ -11,6 +11,7 @@ export const INVALIDATED_PARAM = 'x-sveltekit-invalidated';
|
|
|
11
11
|
* @param {import('types').RequestEvent} event
|
|
12
12
|
* @param {import('types').SSRRoute} route
|
|
13
13
|
* @param {import('types').SSROptions} options
|
|
14
|
+
* @param {import('types').SSRManifest} manifest
|
|
14
15
|
* @param {import('types').SSRState} state
|
|
15
16
|
* @param {boolean[] | undefined} invalidated_data_nodes
|
|
16
17
|
* @param {import('types').TrailingSlash} trailing_slash
|
|
@@ -20,6 +21,7 @@ export async function render_data(
|
|
|
20
21
|
event,
|
|
21
22
|
route,
|
|
22
23
|
options,
|
|
24
|
+
manifest,
|
|
23
25
|
state,
|
|
24
26
|
invalidated_data_nodes,
|
|
25
27
|
trailing_slash
|
|
@@ -54,10 +56,9 @@ export async function render_data(
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
// == because it could be undefined (in dev) or null (in build, because of JSON.stringify)
|
|
57
|
-
const node = n == undefined ? n : await
|
|
59
|
+
const node = n == undefined ? n : await manifest._.nodes[n]();
|
|
58
60
|
return load_server_data({
|
|
59
61
|
event: new_event,
|
|
60
|
-
options,
|
|
61
62
|
state,
|
|
62
63
|
node,
|
|
63
64
|
parent: async () => {
|
|
@@ -54,15 +54,15 @@ export async function render_endpoint(event, mod, state) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return response;
|
|
57
|
-
} catch (
|
|
58
|
-
if (
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (e instanceof Redirect) {
|
|
59
59
|
return new Response(undefined, {
|
|
60
|
-
status:
|
|
61
|
-
headers: { location:
|
|
60
|
+
status: e.status,
|
|
61
|
+
headers: { location: e.location }
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
throw
|
|
65
|
+
throw e;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as set_cookie_parser from 'set-cookie-parser';
|
|
2
|
-
import { respond } from './
|
|
2
|
+
import { respond } from './respond.js';
|
|
3
|
+
import * as paths from '../shared.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @param {{
|
|
6
7
|
* event: import('types').RequestEvent;
|
|
7
8
|
* options: import('types').SSROptions;
|
|
9
|
+
* manifest: import('types').SSRManifest;
|
|
8
10
|
* state: import('types').SSRState;
|
|
9
11
|
* get_cookie_header: (url: URL, header: string | null) => string;
|
|
10
12
|
* }} opts
|
|
11
13
|
* @returns {typeof fetch}
|
|
12
14
|
*/
|
|
13
|
-
export function create_fetch({ event, options, state, get_cookie_header }) {
|
|
15
|
+
export function create_fetch({ event, options, manifest, state, get_cookie_header }) {
|
|
14
16
|
return async (info, init) => {
|
|
15
17
|
const original_request = normalize_fetch_input(info, init, event.url);
|
|
16
18
|
|
|
@@ -71,25 +73,25 @@ export function create_fetch({ event, options, state, get_cookie_header }) {
|
|
|
71
73
|
|
|
72
74
|
// handle fetch requests for static assets. e.g. prebaked data, etc.
|
|
73
75
|
// we need to support everything the browser's fetch supports
|
|
74
|
-
const prefix =
|
|
76
|
+
const prefix = paths.assets || paths.base;
|
|
75
77
|
const decoded = decodeURIComponent(url.pathname);
|
|
76
78
|
const filename = (
|
|
77
79
|
decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded
|
|
78
80
|
).slice(1);
|
|
79
81
|
const filename_html = `${filename}/index.html`; // path may also match path/index.html
|
|
80
82
|
|
|
81
|
-
const is_asset =
|
|
82
|
-
const is_asset_html =
|
|
83
|
+
const is_asset = manifest.assets.has(filename);
|
|
84
|
+
const is_asset_html = manifest.assets.has(filename_html);
|
|
83
85
|
|
|
84
86
|
if (is_asset || is_asset_html) {
|
|
85
87
|
const file = is_asset ? filename : filename_html;
|
|
86
88
|
|
|
87
|
-
if (
|
|
89
|
+
if (state.read) {
|
|
88
90
|
const type = is_asset
|
|
89
|
-
?
|
|
91
|
+
? manifest.mimeTypes[filename.slice(filename.lastIndexOf('.'))]
|
|
90
92
|
: 'text/html';
|
|
91
93
|
|
|
92
|
-
return new Response(
|
|
94
|
+
return new Response(state.read(file), {
|
|
93
95
|
headers: type ? { 'content-type': type } : {}
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -129,7 +131,7 @@ export function create_fetch({ event, options, state, get_cookie_header }) {
|
|
|
129
131
|
);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
response = await respond(request, options, state);
|
|
134
|
+
response = await respond(request, options, manifest, state);
|
|
133
135
|
|
|
134
136
|
const set_cookie = response.headers.get('set-cookie');
|
|
135
137
|
if (set_cookie) {
|