@sveltejs/kit 1.3.10 → 1.4.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 +2 -2
- package/src/constants.js +4 -2
- package/src/core/postbuild/analyse.js +1 -1
- package/src/core/postbuild/crawl.js +2 -2
- package/src/core/postbuild/fallback.js +1 -4
- package/src/core/postbuild/prerender.js +0 -2
- package/src/core/sync/write_server.js +2 -3
- package/src/exports/vite/dev/index.js +3 -6
- package/src/exports/vite/index.js +19 -7
- package/src/exports/vite/preview/index.js +2 -2
- package/src/runtime/app/paths.js +1 -1
- package/src/runtime/client/client.js +13 -7
- package/src/runtime/client/start.js +5 -9
- package/src/runtime/client/utils.js +2 -1
- package/src/runtime/server/endpoint.js +4 -1
- package/src/runtime/server/fetch.js +1 -1
- package/src/runtime/server/page/index.js +1 -1
- package/src/runtime/server/page/render.js +3 -2
- package/src/runtime/server/page/respond_with_error.js +1 -1
- package/src/runtime/server/respond.js +7 -6
- package/src/runtime/server/utils.js +1 -19
- package/src/runtime/shared.js +2 -8
- package/src/utils/options.js +16 -0
- package/types/ambient.d.ts +8 -0
- package/types/index.d.ts +6 -3
- package/types/internal.d.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore && eslint src/**",
|
|
84
84
|
"check": "tsc",
|
|
85
85
|
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
86
|
-
"format": "
|
|
86
|
+
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
|
|
87
87
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
88
88
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
89
89
|
"test:cross-platform:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
|
package/src/constants.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A fake asset path used in `vite dev` and `vite preview`, so that we can
|
|
3
|
+
* serve local assets while verifying that requests are correctly prefixed
|
|
4
|
+
*/
|
|
3
5
|
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
|
|
4
6
|
|
|
5
7
|
export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';
|
|
@@ -165,7 +165,7 @@ export function crawl(html) {
|
|
|
165
165
|
} else if (name === 'rel') {
|
|
166
166
|
rel = value;
|
|
167
167
|
} else if (name === 'src') {
|
|
168
|
-
hrefs.push(value);
|
|
168
|
+
if (value) hrefs.push(value);
|
|
169
169
|
} else if (name === 'srcset') {
|
|
170
170
|
const candidates = [];
|
|
171
171
|
let insideURL = true;
|
|
@@ -183,7 +183,7 @@ export function crawl(html) {
|
|
|
183
183
|
candidates.push(value);
|
|
184
184
|
for (const candidate of candidates) {
|
|
185
185
|
const src = candidate.split(WHITESPACE)[0];
|
|
186
|
-
hrefs.push(src);
|
|
186
|
+
if (src) hrefs.push(src);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
} else {
|
|
@@ -15,9 +15,7 @@ installPolyfills();
|
|
|
15
15
|
const server_root = join(config.outDir, 'output');
|
|
16
16
|
|
|
17
17
|
/** @type {import('types').ServerInternalModule} */
|
|
18
|
-
const { set_building
|
|
19
|
-
pathToFileURL(`${server_root}/server/internal.js`).href
|
|
20
|
-
);
|
|
18
|
+
const { set_building } = await import(pathToFileURL(`${server_root}/server/internal.js`).href);
|
|
21
19
|
|
|
22
20
|
/** @type {import('types').ServerModule} */
|
|
23
21
|
const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
@@ -26,7 +24,6 @@ const { Server } = await import(pathToFileURL(`${server_root}/server/index.js`).
|
|
|
26
24
|
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
27
25
|
|
|
28
26
|
set_building(true);
|
|
29
|
-
set_paths(config.paths);
|
|
30
27
|
|
|
31
28
|
const server = new Server(manifest);
|
|
32
29
|
await server.init({ env: JSON.parse(env) });
|
|
@@ -100,8 +100,6 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
|
|
|
100
100
|
/** @type {Map<string, string>} */
|
|
101
101
|
const saved = new Map();
|
|
102
102
|
|
|
103
|
-
internal.set_paths(config.paths);
|
|
104
|
-
|
|
105
103
|
const server = new Server(manifest);
|
|
106
104
|
await server.init({ env });
|
|
107
105
|
|
|
@@ -25,9 +25,8 @@ const server_template = ({
|
|
|
25
25
|
error_page
|
|
26
26
|
}) => `
|
|
27
27
|
import root from '../root.svelte';
|
|
28
|
-
import {
|
|
28
|
+
import { set_assets, set_building, set_private_env, set_public_env, set_version } from '${runtime_directory}/shared.js';
|
|
29
29
|
|
|
30
|
-
set_paths(${s(config.kit.paths)});
|
|
31
30
|
set_version(${s(config.kit.version.name)});
|
|
32
31
|
|
|
33
32
|
export const options = {
|
|
@@ -58,7 +57,7 @@ export function get_hooks() {
|
|
|
58
57
|
return ${hooks ? `import(${s(hooks)})` : '{}'};
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export {
|
|
60
|
+
export { set_assets, set_building, set_private_env, set_public_env };
|
|
62
61
|
`;
|
|
63
62
|
|
|
64
63
|
// TODO need to re-run this whenever src/app.html or src/error.html are
|
|
@@ -438,20 +438,17 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
438
438
|
return;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
// we have to import `Server` before calling `
|
|
441
|
+
// we have to import `Server` before calling `set_assets`
|
|
442
442
|
const { Server } = /** @type {import('types').ServerModule} */ (
|
|
443
443
|
await vite.ssrLoadModule(`${runtime_base}/server/index.js`)
|
|
444
444
|
);
|
|
445
445
|
|
|
446
|
-
const {
|
|
446
|
+
const { set_assets, set_version, set_fix_stack_trace } =
|
|
447
447
|
/** @type {import('types').ServerInternalModule} */ (
|
|
448
448
|
await vite.ssrLoadModule(`${runtime_base}/shared.js`)
|
|
449
449
|
);
|
|
450
450
|
|
|
451
|
-
|
|
452
|
-
base: svelte_config.kit.paths.base,
|
|
453
|
-
assets
|
|
454
|
-
});
|
|
451
|
+
set_assets(assets);
|
|
455
452
|
|
|
456
453
|
set_version(svelte_config.kit.version.name);
|
|
457
454
|
|
|
@@ -22,6 +22,7 @@ import { get_config_aliases, get_env } from './utils.js';
|
|
|
22
22
|
import { write_client_manifest } from '../../core/sync/write_client_manifest.js';
|
|
23
23
|
import prerender from '../../core/postbuild/prerender.js';
|
|
24
24
|
import analyse from '../../core/postbuild/analyse.js';
|
|
25
|
+
import { s } from '../../utils/misc.js';
|
|
25
26
|
|
|
26
27
|
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
27
28
|
|
|
@@ -253,9 +254,9 @@ function kit({ svelte_config }) {
|
|
|
253
254
|
new_config.build.ssr = !secondary_build_started;
|
|
254
255
|
|
|
255
256
|
new_config.define = {
|
|
256
|
-
__SVELTEKIT_ADAPTER_NAME__:
|
|
257
|
-
__SVELTEKIT_APP_VERSION_FILE__:
|
|
258
|
-
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__:
|
|
257
|
+
__SVELTEKIT_ADAPTER_NAME__: s(kit.adapter?.name),
|
|
258
|
+
__SVELTEKIT_APP_VERSION_FILE__: s(`${kit.appDir}/version.json`),
|
|
259
|
+
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval),
|
|
259
260
|
__SVELTEKIT_DEV__: 'false',
|
|
260
261
|
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false'
|
|
261
262
|
};
|
|
@@ -315,7 +316,9 @@ function kit({ svelte_config }) {
|
|
|
315
316
|
|
|
316
317
|
async resolveId(id) {
|
|
317
318
|
// treat $env/static/[public|private] as virtual
|
|
318
|
-
if (id.startsWith('$env/') || id === '$service-worker')
|
|
319
|
+
if (id.startsWith('$env/') || id === '$internal/paths' || id === '$service-worker') {
|
|
320
|
+
return `\0${id}`;
|
|
321
|
+
}
|
|
319
322
|
},
|
|
320
323
|
|
|
321
324
|
async load(id, options) {
|
|
@@ -351,6 +354,15 @@ function kit({ svelte_config }) {
|
|
|
351
354
|
);
|
|
352
355
|
case '\0$service-worker':
|
|
353
356
|
return create_service_worker_module(svelte_config);
|
|
357
|
+
case '\0$internal/paths':
|
|
358
|
+
const { assets, base } = svelte_config.kit.paths;
|
|
359
|
+
return `export const base = ${s(base)};
|
|
360
|
+
export let assets = ${s(assets)};
|
|
361
|
+
|
|
362
|
+
/** @param {string} path */
|
|
363
|
+
export function set_assets(path) {
|
|
364
|
+
assets = path;
|
|
365
|
+
}`;
|
|
354
366
|
}
|
|
355
367
|
}
|
|
356
368
|
};
|
|
@@ -552,7 +564,7 @@ function kit({ svelte_config }) {
|
|
|
552
564
|
this.emitFile({
|
|
553
565
|
type: 'asset',
|
|
554
566
|
fileName: `${kit.appDir}/version.json`,
|
|
555
|
-
source:
|
|
567
|
+
source: s({ version: kit.version.name })
|
|
556
568
|
});
|
|
557
569
|
},
|
|
558
570
|
|
|
@@ -788,9 +800,9 @@ export const build = [];
|
|
|
788
800
|
export const files = [
|
|
789
801
|
${create_assets(config)
|
|
790
802
|
.filter((asset) => config.kit.serviceWorker.files(asset.file))
|
|
791
|
-
.map((asset) => `${
|
|
803
|
+
.map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
|
|
792
804
|
.join(',\n\t\t\t\t')}
|
|
793
805
|
];
|
|
794
806
|
export const prerendered = [];
|
|
795
|
-
export const version = ${
|
|
807
|
+
export const version = ${s(config.kit.version.name)};
|
|
796
808
|
`;
|
|
@@ -37,14 +37,14 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
37
37
|
const dir = join(svelte_config.kit.outDir, 'output/server');
|
|
38
38
|
|
|
39
39
|
/** @type {import('types').ServerInternalModule} */
|
|
40
|
-
const {
|
|
40
|
+
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
|
|
41
41
|
|
|
42
42
|
/** @type {import('types').ServerModule} */
|
|
43
43
|
const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
|
|
44
44
|
|
|
45
45
|
const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
set_assets(assets);
|
|
48
48
|
|
|
49
49
|
const server = new Server(manifest);
|
|
50
50
|
await server.init({
|
package/src/runtime/app/paths.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { base, assets } from '
|
|
1
|
+
export { base, assets } from '$internal/paths';
|
|
@@ -26,6 +26,7 @@ import { parse } from './parse.js';
|
|
|
26
26
|
|
|
27
27
|
import Root from '__GENERATED__/root.svelte';
|
|
28
28
|
import { nodes, server_loads, dictionary, matchers, hooks } from '__CLIENT__/manifest.js';
|
|
29
|
+
import { base } from '$internal/paths';
|
|
29
30
|
import { HttpError, Redirect } from '../control.js';
|
|
30
31
|
import { stores } from './singletons.js';
|
|
31
32
|
import { unwrap_promises } from '../../utils/promises.js';
|
|
@@ -66,11 +67,10 @@ function update_scroll_positions(index) {
|
|
|
66
67
|
/**
|
|
67
68
|
* @param {{
|
|
68
69
|
* target: HTMLElement;
|
|
69
|
-
* base: string;
|
|
70
70
|
* }} opts
|
|
71
71
|
* @returns {import('./types').Client}
|
|
72
72
|
*/
|
|
73
|
-
export function create_client({ target
|
|
73
|
+
export function create_client({ target }) {
|
|
74
74
|
const container = __SVELTEKIT_EMBEDDED__ ? target : document.documentElement;
|
|
75
75
|
/** @type {Array<((url: URL) => boolean)>} */
|
|
76
76
|
const invalidated = [];
|
|
@@ -594,12 +594,17 @@ export function create_client({ target, base }) {
|
|
|
594
594
|
}
|
|
595
595
|
|
|
596
596
|
// we must fixup relative urls so they are resolved from the target page
|
|
597
|
-
const resolved = new URL(requested, url)
|
|
598
|
-
depends(resolved);
|
|
597
|
+
const resolved = new URL(requested, url);
|
|
598
|
+
depends(resolved.href);
|
|
599
|
+
|
|
600
|
+
// match ssr serialized data url, which is important to find cached responses
|
|
601
|
+
if (resolved.origin === url.origin) {
|
|
602
|
+
requested = resolved.href.slice(url.origin.length);
|
|
603
|
+
}
|
|
599
604
|
|
|
600
605
|
// prerendered pages may be served from any origin, so `initial_fetch` urls shouldn't be resolved
|
|
601
606
|
return started
|
|
602
|
-
? subsequent_fetch(requested, resolved, init)
|
|
607
|
+
? subsequent_fetch(requested, resolved.href, init)
|
|
603
608
|
: initial_fetch(requested, init);
|
|
604
609
|
},
|
|
605
610
|
setHeaders: () => {}, // noop
|
|
@@ -745,7 +750,7 @@ export function create_client({ target, base }) {
|
|
|
745
750
|
server_data = await load_data(url, invalid_server_nodes);
|
|
746
751
|
} catch (error) {
|
|
747
752
|
return load_root_error_page({
|
|
748
|
-
status: 500,
|
|
753
|
+
status: error instanceof HttpError ? error.status : 500,
|
|
749
754
|
error: await handle_error(error, { url, params, route: { id: route.id } }),
|
|
750
755
|
url,
|
|
751
756
|
route
|
|
@@ -1693,7 +1698,8 @@ async function load_data(url, invalid) {
|
|
|
1693
1698
|
|
|
1694
1699
|
if (!res.ok) {
|
|
1695
1700
|
// error message is a JSON-stringified string which devalue can't handle at the top level
|
|
1696
|
-
|
|
1701
|
+
// turn it into a HttpError to not call handleError on the client again (was already handled on the server)
|
|
1702
|
+
throw new HttpError(res.status, data);
|
|
1697
1703
|
}
|
|
1698
1704
|
|
|
1699
1705
|
// revive devalue-flattened data
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
2
|
import { create_client } from './client.js';
|
|
3
3
|
import { init } from './singletons.js';
|
|
4
|
-
import {
|
|
4
|
+
import { set_assets, set_version, set_public_env } from '../shared.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {{
|
|
8
|
+
* assets: string;
|
|
8
9
|
* env: Record<string, string>;
|
|
9
10
|
* hydrate: Parameters<import('./types').Client['_hydrate']>[0];
|
|
10
|
-
* paths: {
|
|
11
|
-
* assets: string;
|
|
12
|
-
* base: string;
|
|
13
|
-
* },
|
|
14
11
|
* target: HTMLElement;
|
|
15
12
|
* version: string;
|
|
16
13
|
* }} opts
|
|
17
14
|
*/
|
|
18
|
-
export async function start({ env, hydrate,
|
|
15
|
+
export async function start({ assets, env, hydrate, target, version }) {
|
|
19
16
|
set_public_env(env);
|
|
20
|
-
|
|
17
|
+
set_assets(assets);
|
|
21
18
|
set_version(version);
|
|
22
19
|
|
|
23
20
|
if (DEV && target === document.body) {
|
|
@@ -27,8 +24,7 @@ export async function start({ env, hydrate, paths, target, version }) {
|
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
const client = create_client({
|
|
30
|
-
target
|
|
31
|
-
base: paths.base
|
|
27
|
+
target
|
|
32
28
|
});
|
|
33
29
|
|
|
34
30
|
init({ client });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BROWSER, DEV } from 'esm-env';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
|
-
import { assets
|
|
3
|
+
import { assets } from '$internal/paths';
|
|
4
|
+
import { version } from '../shared.js';
|
|
4
5
|
import { PRELOAD_PRIORITIES } from './constants.js';
|
|
5
6
|
|
|
6
7
|
/* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
|
@@ -4,11 +4,12 @@ import { method_not_allowed } from './utils.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {import('types').RequestEvent} event
|
|
7
|
+
* @param {import('types').SSRRoute} route
|
|
7
8
|
* @param {import('types').SSREndpoint} mod
|
|
8
9
|
* @param {import('types').SSRState} state
|
|
9
10
|
* @returns {Promise<Response>}
|
|
10
11
|
*/
|
|
11
|
-
export async function render_endpoint(event, mod, state) {
|
|
12
|
+
export async function render_endpoint(event, route, mod, state) {
|
|
12
13
|
const method = /** @type {import('types').HttpMethod} */ (event.request.method);
|
|
13
14
|
|
|
14
15
|
let handler = mod[method];
|
|
@@ -38,6 +39,8 @@ export async function render_endpoint(event, mod, state) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
state.initiator = route;
|
|
43
|
+
|
|
41
44
|
try {
|
|
42
45
|
const response = await handler(
|
|
43
46
|
/** @type {import('types').RequestEvent<Record<string, any>>} */ (event)
|
|
@@ -4,7 +4,6 @@ import { normalize_error } from '../../../utils/error.js';
|
|
|
4
4
|
import { add_data_suffix } from '../../../utils/url.js';
|
|
5
5
|
import { HttpError, Redirect } from '../../control.js';
|
|
6
6
|
import {
|
|
7
|
-
get_option,
|
|
8
7
|
redirect_response,
|
|
9
8
|
static_error_page,
|
|
10
9
|
handle_error_and_jsonify,
|
|
@@ -19,6 +18,7 @@ import {
|
|
|
19
18
|
import { load_data, load_server_data } from './load_data.js';
|
|
20
19
|
import { render_response } from './render.js';
|
|
21
20
|
import { respond_with_error } from './respond_with_error.js';
|
|
21
|
+
import { get_option } from '../../../utils/options.js';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @param {import('types').RequestEvent} event
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
2
|
import { readable, writable } from 'svelte/store';
|
|
3
3
|
import { DEV } from 'esm-env';
|
|
4
|
+
import { assets, base } from '$internal/paths';
|
|
4
5
|
import { hash } from '../../hash.js';
|
|
5
6
|
import { serialize_data } from './serialize_data.js';
|
|
6
7
|
import { s } from '../../../utils/misc.js';
|
|
7
8
|
import { Csp } from './csp.js';
|
|
8
9
|
import { uneval_action_response } from './actions.js';
|
|
9
10
|
import { clarify_devalue_error } from '../utils.js';
|
|
10
|
-
import {
|
|
11
|
+
import { version, public_env } from '../../shared.js';
|
|
11
12
|
import { text } from '../../../exports/index.js';
|
|
12
13
|
|
|
13
14
|
// TODO rename this function/module
|
|
@@ -265,8 +266,8 @@ export async function render_response({
|
|
|
265
266
|
|
|
266
267
|
if (page_config.csr) {
|
|
267
268
|
const opts = [
|
|
269
|
+
`assets: ${s(assets)}`,
|
|
268
270
|
`env: ${s(public_env)}`,
|
|
269
|
-
`paths: ${s({ assets, base })}`,
|
|
270
271
|
`target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode`,
|
|
271
272
|
`version: ${s(version)}`
|
|
272
273
|
];
|
|
@@ -2,11 +2,11 @@ import { render_response } from './render.js';
|
|
|
2
2
|
import { load_data, load_server_data } from './load_data.js';
|
|
3
3
|
import {
|
|
4
4
|
handle_error_and_jsonify,
|
|
5
|
-
get_option,
|
|
6
5
|
static_error_page,
|
|
7
6
|
redirect_response,
|
|
8
7
|
GENERIC_ERROR
|
|
9
8
|
} from '../utils.js';
|
|
9
|
+
import { get_option } from '../../../utils/options.js';
|
|
10
10
|
import { HttpError, Redirect } from '../../control.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
|
+
import { base } from '$internal/paths';
|
|
2
3
|
import { is_endpoint_request, render_endpoint } from './endpoint.js';
|
|
3
4
|
import { render_page } from './page/index.js';
|
|
4
5
|
import { render_response } from './page/render.js';
|
|
5
6
|
import { respond_with_error } from './page/respond_with_error.js';
|
|
6
7
|
import { is_form_content_type } from '../../utils/http.js';
|
|
7
|
-
import { GENERIC_ERROR,
|
|
8
|
+
import { GENERIC_ERROR, handle_fatal_error, redirect_response } from './utils.js';
|
|
8
9
|
import {
|
|
9
10
|
decode_pathname,
|
|
10
11
|
decode_params,
|
|
@@ -23,8 +24,8 @@ import {
|
|
|
23
24
|
validate_page_server_exports,
|
|
24
25
|
validate_server_exports
|
|
25
26
|
} from '../../utils/exports.js';
|
|
27
|
+
import { get_option } from '../../utils/options.js';
|
|
26
28
|
import { error, json, text } from '../../exports/index.js';
|
|
27
|
-
import * as paths from '../shared.js';
|
|
28
29
|
|
|
29
30
|
/* global __SVELTEKIT_ADAPTER_NAME__ */
|
|
30
31
|
|
|
@@ -70,11 +71,11 @@ export async function respond(request, options, manifest, state) {
|
|
|
70
71
|
/** @type {Record<string, string>} */
|
|
71
72
|
let params = {};
|
|
72
73
|
|
|
73
|
-
if (
|
|
74
|
-
if (!decoded.startsWith(
|
|
74
|
+
if (base && !state.prerendering?.fallback) {
|
|
75
|
+
if (!decoded.startsWith(base)) {
|
|
75
76
|
return text('Not found', { status: 404 });
|
|
76
77
|
}
|
|
77
|
-
decoded = decoded.slice(
|
|
78
|
+
decoded = decoded.slice(base.length) || '/';
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
const is_data_request = has_data_suffix(decoded);
|
|
@@ -357,7 +358,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
357
358
|
trailing_slash ?? 'never'
|
|
358
359
|
);
|
|
359
360
|
} else if (route.endpoint && (!route.page || is_endpoint_request(event))) {
|
|
360
|
-
response = await render_endpoint(event, await route.endpoint(), state);
|
|
361
|
+
response = await render_endpoint(event, route, await route.endpoint(), state);
|
|
361
362
|
} else if (route.page) {
|
|
362
363
|
response = await render_page(
|
|
363
364
|
event,
|
|
@@ -2,7 +2,6 @@ import * as devalue from 'devalue';
|
|
|
2
2
|
import { json, text } from '../../exports/index.js';
|
|
3
3
|
import { coalesce_to_error } from '../../utils/error.js';
|
|
4
4
|
import { negotiate } from '../../utils/http.js';
|
|
5
|
-
import { has_data_suffix } from '../../utils/url.js';
|
|
6
5
|
import { HttpError } from '../control.js';
|
|
7
6
|
import { fix_stack_trace } from '../shared.js';
|
|
8
7
|
|
|
@@ -51,23 +50,6 @@ export function allowed_methods(mod) {
|
|
|
51
50
|
return allowed;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
/**
|
|
55
|
-
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
56
|
-
* @template {Option extends 'prerender' ? import('types').PrerenderOption : Option extends 'trailingSlash' ? import('types').TrailingSlash : boolean} Value
|
|
57
|
-
*
|
|
58
|
-
* @param {Array<import('types').SSRNode | undefined>} nodes
|
|
59
|
-
* @param {Option} option
|
|
60
|
-
*
|
|
61
|
-
* @returns {Value | undefined}
|
|
62
|
-
*/
|
|
63
|
-
export function get_option(nodes, option) {
|
|
64
|
-
return nodes.reduce((value, node) => {
|
|
65
|
-
return /** @type {any} TypeScript's too dumb to understand this */ (
|
|
66
|
-
node?.universal?.[option] ?? node?.server?.[option] ?? value
|
|
67
|
-
);
|
|
68
|
-
}, /** @type {Value | undefined} */ (undefined));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
53
|
/**
|
|
72
54
|
* Return as a response that renders the error.html
|
|
73
55
|
*
|
|
@@ -98,7 +80,7 @@ export async function handle_fatal_error(event, options, error) {
|
|
|
98
80
|
'text/html'
|
|
99
81
|
]);
|
|
100
82
|
|
|
101
|
-
if (
|
|
83
|
+
if (event.isDataRequest || type === 'application/json') {
|
|
102
84
|
return json(body, {
|
|
103
85
|
status
|
|
104
86
|
});
|
package/src/runtime/shared.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export { set_assets } from '$internal/paths';
|
|
2
|
+
|
|
3
3
|
export let building = false;
|
|
4
4
|
export let version = '';
|
|
5
5
|
|
|
@@ -12,12 +12,6 @@ export let public_env = {};
|
|
|
12
12
|
/** @param {string} stack */
|
|
13
13
|
export let fix_stack_trace = (stack) => stack;
|
|
14
14
|
|
|
15
|
-
/** @param {{ base: string, assets: string }} paths */
|
|
16
|
-
export function set_paths(paths) {
|
|
17
|
-
base = paths.base;
|
|
18
|
-
assets = paths.assets || base;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
15
|
/** @param {boolean} value */
|
|
22
16
|
export function set_building(value) {
|
|
23
17
|
building = value;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
3
|
+
* @template {Option extends 'prerender' ? import('types').PrerenderOption : Option extends 'trailingSlash' ? import('types').TrailingSlash : boolean} Value
|
|
4
|
+
*
|
|
5
|
+
* @param {Array<import('types').SSRNode | undefined>} nodes
|
|
6
|
+
* @param {Option} option
|
|
7
|
+
*
|
|
8
|
+
* @returns {Value | undefined}
|
|
9
|
+
*/
|
|
10
|
+
export function get_option(nodes, option) {
|
|
11
|
+
return nodes.reduce((value, node) => {
|
|
12
|
+
return /** @type {any} TypeScript's too dumb to understand this */ (
|
|
13
|
+
node?.universal?.[option] ?? node?.server?.[option] ?? value
|
|
14
|
+
);
|
|
15
|
+
}, /** @type {Value | undefined} */ (undefined));
|
|
16
|
+
}
|
package/types/ambient.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ declare module '$app/navigation' {
|
|
|
170
170
|
export function disableScrollHandling(): void;
|
|
171
171
|
/**
|
|
172
172
|
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
|
|
173
|
+
* For external URLs, use `window.location = url` instead of calling `goto(url)`.
|
|
173
174
|
*
|
|
174
175
|
* @param url Where to navigate to. Note that if you've set [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
|
|
175
176
|
* @param opts Options related to the navigation
|
|
@@ -431,3 +432,10 @@ declare module '@sveltejs/kit/vite' {
|
|
|
431
432
|
export function sveltekit(): Promise<Plugin[]>;
|
|
432
433
|
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
433
434
|
}
|
|
435
|
+
|
|
436
|
+
/** Internal version of $app/paths */
|
|
437
|
+
declare module '$internal/paths' {
|
|
438
|
+
export const base: `/${string}`;
|
|
439
|
+
export let assets: `https://${string}` | `http://${string}`;
|
|
440
|
+
export function set_assets(path: string): void;
|
|
441
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -50,9 +50,11 @@ export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
|
50
50
|
? OptionalUnion<AwaitedPropertiesUnion<input>>
|
|
51
51
|
: AwaitedPropertiesUnion<input>;
|
|
52
52
|
|
|
53
|
-
export type AwaitedActions<T extends Record<string, (...args: any) => any>> =
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
export type AwaitedActions<T extends Record<string, (...args: any) => any>> = OptionalUnion<
|
|
54
|
+
{
|
|
55
|
+
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
|
|
56
|
+
}[keyof T]
|
|
57
|
+
>;
|
|
56
58
|
|
|
57
59
|
// Takes a union type and returns a union type where each type also has all properties
|
|
58
60
|
// of all possible types (typed as undefined), making accessing them more ergonomic
|
|
@@ -453,6 +455,7 @@ export interface KitConfig {
|
|
|
453
455
|
* - `(details) => void` — a custom error handler that takes a `details` object with `status`, `path`, `referrer`, `referenceType` and `message` properties. If you `throw` from this function, the build will fail
|
|
454
456
|
*
|
|
455
457
|
* ```js
|
|
458
|
+
* /// file: svelte.config.js
|
|
456
459
|
* /// type: import('@sveltejs/kit').Config
|
|
457
460
|
* const config = {
|
|
458
461
|
* kit: {
|
package/types/internal.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OutputChunk } from 'rollup';
|
|
2
1
|
import { SvelteComponent } from 'svelte/internal';
|
|
3
2
|
import {
|
|
4
3
|
Config,
|
|
@@ -30,7 +29,7 @@ export interface ServerModule {
|
|
|
30
29
|
|
|
31
30
|
export interface ServerInternalModule {
|
|
32
31
|
set_building(building: boolean): void;
|
|
33
|
-
|
|
32
|
+
set_assets(path: string): void;
|
|
34
33
|
set_private_env(environment: Record<string, string>): void;
|
|
35
34
|
set_public_env(environment: Record<string, string>): void;
|
|
36
35
|
set_version(version: string): void;
|