@sveltejs/kit 1.0.0-next.352 → 1.0.0-next.355
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/app/env.js +13 -1
- package/assets/client/start.js +5 -3
- package/assets/server/index.js +78 -78
- package/dist/chunks/error.js +673 -0
- package/dist/chunks/index.js +15519 -1138
- package/dist/chunks/index2.js +177 -101
- package/dist/chunks/sync.js +180 -9
- package/dist/chunks/write_tsconfig.js +108 -3
- package/dist/cli.js +45 -830
- package/dist/vite.js +3011 -0
- package/package.json +4 -1
- package/types/ambient.d.ts +48 -10
- package/dist/chunks/constants.js +0 -663
- package/dist/chunks/filesystem.js +0 -110
- package/dist/chunks/index3.js +0 -183
- package/dist/chunks/index4.js +0 -215
- package/dist/chunks/index5.js +0 -15748
- package/dist/chunks/misc.js +0 -78
- package/dist/chunks/object.js +0 -83
- package/dist/chunks/plugin.js +0 -558
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import fs__default from 'fs';
|
|
2
|
-
import path__default from 'path';
|
|
3
|
-
|
|
4
|
-
/** @param {string} dir */
|
|
5
|
-
function mkdirp(dir) {
|
|
6
|
-
try {
|
|
7
|
-
fs__default.mkdirSync(dir, { recursive: true });
|
|
8
|
-
} catch (/** @type {any} */ e) {
|
|
9
|
-
if (e.code === 'EEXIST') return;
|
|
10
|
-
throw e;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** @param {string} path */
|
|
15
|
-
function rimraf(path) {
|
|
16
|
-
fs__default.rmSync(path, { force: true, recursive: true });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param {string} source
|
|
21
|
-
* @param {string} target
|
|
22
|
-
* @param {{
|
|
23
|
-
* filter?: (basename: string) => boolean;
|
|
24
|
-
* replace?: Record<string, string>;
|
|
25
|
-
* }} opts
|
|
26
|
-
*/
|
|
27
|
-
function copy(source, target, opts = {}) {
|
|
28
|
-
if (!fs__default.existsSync(source)) return [];
|
|
29
|
-
|
|
30
|
-
/** @type {string[]} */
|
|
31
|
-
const files = [];
|
|
32
|
-
|
|
33
|
-
const prefix = posixify(target) + '/';
|
|
34
|
-
|
|
35
|
-
const regex = opts.replace
|
|
36
|
-
? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
|
|
37
|
-
: null;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {string} from
|
|
41
|
-
* @param {string} to
|
|
42
|
-
*/
|
|
43
|
-
function go(from, to) {
|
|
44
|
-
if (opts.filter && !opts.filter(path__default.basename(from))) return;
|
|
45
|
-
|
|
46
|
-
const stats = fs__default.statSync(from);
|
|
47
|
-
|
|
48
|
-
if (stats.isDirectory()) {
|
|
49
|
-
fs__default.readdirSync(from).forEach((file) => {
|
|
50
|
-
go(path__default.join(from, file), path__default.join(to, file));
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
mkdirp(path__default.dirname(to));
|
|
54
|
-
|
|
55
|
-
if (opts.replace) {
|
|
56
|
-
const data = fs__default.readFileSync(from, 'utf-8');
|
|
57
|
-
fs__default.writeFileSync(
|
|
58
|
-
to,
|
|
59
|
-
data.replace(
|
|
60
|
-
/** @type {RegExp} */ (regex),
|
|
61
|
-
(match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
|
|
62
|
-
)
|
|
63
|
-
);
|
|
64
|
-
} else {
|
|
65
|
-
fs__default.copyFileSync(from, to);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
go(source, target);
|
|
73
|
-
|
|
74
|
-
return files;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get a list of all files in a directory
|
|
79
|
-
* @param {string} cwd - the directory to walk
|
|
80
|
-
* @param {boolean} [dirs] - whether to include directories in the result
|
|
81
|
-
*/
|
|
82
|
-
function walk(cwd, dirs = false) {
|
|
83
|
-
/** @type {string[]} */
|
|
84
|
-
const all_files = [];
|
|
85
|
-
|
|
86
|
-
/** @param {string} dir */
|
|
87
|
-
function walk_dir(dir) {
|
|
88
|
-
const files = fs__default.readdirSync(path__default.join(cwd, dir));
|
|
89
|
-
|
|
90
|
-
for (const file of files) {
|
|
91
|
-
const joined = path__default.join(dir, file);
|
|
92
|
-
const stats = fs__default.statSync(path__default.join(cwd, joined));
|
|
93
|
-
if (stats.isDirectory()) {
|
|
94
|
-
if (dirs) all_files.push(joined);
|
|
95
|
-
walk_dir(joined);
|
|
96
|
-
} else {
|
|
97
|
-
all_files.push(joined);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return walk_dir(''), all_files;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** @param {string} str */
|
|
106
|
-
function posixify(str) {
|
|
107
|
-
return str.replace(/\\/g, '/');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export { copy as c, mkdirp as m, posixify as p, rimraf as r, walk as w };
|
package/dist/chunks/index3.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { $ } from '../cli.js';
|
|
2
|
-
import { r as rimraf, m as mkdirp, c as copy } from './filesystem.js';
|
|
3
|
-
import { g as generate_manifest } from './index2.js';
|
|
4
|
-
import 'chokidar';
|
|
5
|
-
import 'fs';
|
|
6
|
-
import 'path';
|
|
7
|
-
import 'sade';
|
|
8
|
-
import 'vite';
|
|
9
|
-
import 'url';
|
|
10
|
-
import 'os';
|
|
11
|
-
import './misc.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates the Builder which is passed to adapters for building the application.
|
|
15
|
-
* @param {{
|
|
16
|
-
* config: import('types').ValidatedConfig;
|
|
17
|
-
* build_data: import('types').BuildData;
|
|
18
|
-
* prerendered: import('types').Prerendered;
|
|
19
|
-
* log: import('types').Logger;
|
|
20
|
-
* }} opts
|
|
21
|
-
* @returns {import('types').Builder}
|
|
22
|
-
*/
|
|
23
|
-
function create_builder({ config, build_data, prerendered, log }) {
|
|
24
|
-
/** @type {Set<string>} */
|
|
25
|
-
const prerendered_paths = new Set(prerendered.paths);
|
|
26
|
-
|
|
27
|
-
/** @param {import('types').RouteData} route */
|
|
28
|
-
// TODO routes should come pre-filtered
|
|
29
|
-
function not_prerendered(route) {
|
|
30
|
-
if (route.type === 'page' && route.path) {
|
|
31
|
-
return !prerendered_paths.has(route.path);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
log,
|
|
39
|
-
rimraf,
|
|
40
|
-
mkdirp,
|
|
41
|
-
copy,
|
|
42
|
-
|
|
43
|
-
config,
|
|
44
|
-
prerendered,
|
|
45
|
-
|
|
46
|
-
async createEntries(fn) {
|
|
47
|
-
const { routes } = build_data.manifest_data;
|
|
48
|
-
|
|
49
|
-
/** @type {import('types').RouteDefinition[]} */
|
|
50
|
-
const facades = routes.map((route) => ({
|
|
51
|
-
id: route.id,
|
|
52
|
-
type: route.type,
|
|
53
|
-
segments: route.id.split('/').map((segment) => ({
|
|
54
|
-
dynamic: segment.includes('['),
|
|
55
|
-
rest: segment.includes('[...'),
|
|
56
|
-
content: segment
|
|
57
|
-
})),
|
|
58
|
-
pattern: route.pattern,
|
|
59
|
-
methods: route.type === 'page' ? ['get'] : build_data.server.methods[route.file]
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
const seen = new Set();
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < routes.length; i += 1) {
|
|
65
|
-
const route = routes[i];
|
|
66
|
-
const { id, filter, complete } = fn(facades[i]);
|
|
67
|
-
|
|
68
|
-
if (seen.has(id)) continue;
|
|
69
|
-
seen.add(id);
|
|
70
|
-
|
|
71
|
-
const group = [route];
|
|
72
|
-
|
|
73
|
-
// figure out which lower priority routes should be considered fallbacks
|
|
74
|
-
for (let j = i + 1; j < routes.length; j += 1) {
|
|
75
|
-
if (filter(facades[j])) {
|
|
76
|
-
group.push(routes[j]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const filtered = new Set(group.filter(not_prerendered));
|
|
81
|
-
|
|
82
|
-
// heuristic: if /foo/[bar] is included, /foo/[bar].json should
|
|
83
|
-
// also be included, since the page likely needs the endpoint
|
|
84
|
-
filtered.forEach((route) => {
|
|
85
|
-
if (route.type === 'page') {
|
|
86
|
-
const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
|
|
87
|
-
|
|
88
|
-
if (endpoint) {
|
|
89
|
-
filtered.add(endpoint);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
if (filtered.size > 0) {
|
|
95
|
-
await complete({
|
|
96
|
-
generateManifest: ({ relativePath, format }) =>
|
|
97
|
-
generate_manifest({
|
|
98
|
-
build_data,
|
|
99
|
-
relative_path: relativePath,
|
|
100
|
-
routes: Array.from(filtered),
|
|
101
|
-
format
|
|
102
|
-
})
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
generateManifest: ({ relativePath, format }) => {
|
|
109
|
-
return generate_manifest({
|
|
110
|
-
build_data,
|
|
111
|
-
relative_path: relativePath,
|
|
112
|
-
routes: build_data.manifest_data.routes.filter(not_prerendered),
|
|
113
|
-
format
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
getBuildDirectory(name) {
|
|
118
|
-
return `${config.kit.outDir}/${name}`;
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
getClientDirectory() {
|
|
122
|
-
return `${config.kit.outDir}/output/client`;
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
getServerDirectory() {
|
|
126
|
-
return `${config.kit.outDir}/output/server`;
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
getStaticDirectory() {
|
|
130
|
-
return config.kit.files.assets;
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
writeClient(dest) {
|
|
134
|
-
return copy(`${config.kit.outDir}/output/client`, dest);
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
writePrerendered(dest, { fallback } = {}) {
|
|
138
|
-
const source = `${config.kit.outDir}/output/prerendered`;
|
|
139
|
-
const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
|
|
140
|
-
|
|
141
|
-
if (fallback) {
|
|
142
|
-
files.push(fallback);
|
|
143
|
-
copy(`${source}/fallback.html`, `${dest}/${fallback}`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return files;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
writeServer(dest) {
|
|
150
|
-
return copy(`${config.kit.outDir}/output/server`, dest);
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
writeStatic(dest) {
|
|
154
|
-
return copy(config.kit.files.assets, dest);
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
// @ts-expect-error
|
|
158
|
-
async prerender() {
|
|
159
|
-
throw new Error(
|
|
160
|
-
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @param {import('types').ValidatedConfig} config
|
|
168
|
-
* @param {import('types').BuildData} build_data
|
|
169
|
-
* @param {import('types').Prerendered} prerendered
|
|
170
|
-
* @param {{ log: import('types').Logger }} opts
|
|
171
|
-
*/
|
|
172
|
-
async function adapt(config, build_data, prerendered, { log }) {
|
|
173
|
-
const { name, adapt } = config.kit.adapter;
|
|
174
|
-
|
|
175
|
-
console.log($.bold().cyan(`\n> Using ${name}`));
|
|
176
|
-
|
|
177
|
-
const builder = create_builder({ config, build_data, prerendered, log });
|
|
178
|
-
await adapt(builder);
|
|
179
|
-
|
|
180
|
-
log.success('done');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export { adapt };
|
package/dist/chunks/index4.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import fs__default from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
import { getRequest, setResponse } from '../node.js';
|
|
6
|
-
import { installPolyfills } from '../node/polyfills.js';
|
|
7
|
-
import { d as load_config } from '../cli.js';
|
|
8
|
-
import 'querystring';
|
|
9
|
-
import 'stream';
|
|
10
|
-
import 'node:http';
|
|
11
|
-
import 'node:https';
|
|
12
|
-
import 'node:zlib';
|
|
13
|
-
import 'node:stream';
|
|
14
|
-
import 'node:buffer';
|
|
15
|
-
import 'node:util';
|
|
16
|
-
import 'node:url';
|
|
17
|
-
import 'node:net';
|
|
18
|
-
import 'node:fs';
|
|
19
|
-
import 'node:path';
|
|
20
|
-
import 'crypto';
|
|
21
|
-
import 'chokidar';
|
|
22
|
-
import 'sade';
|
|
23
|
-
import 'vite';
|
|
24
|
-
import 'os';
|
|
25
|
-
|
|
26
|
-
/** @typedef {import('http').IncomingMessage} Req */
|
|
27
|
-
/** @typedef {import('http').ServerResponse} Res */
|
|
28
|
-
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
|
|
29
|
-
|
|
30
|
-
/** @type {import('types').ValidatedConfig} */
|
|
31
|
-
let config;
|
|
32
|
-
|
|
33
|
-
/** @type {boolean} */
|
|
34
|
-
let https;
|
|
35
|
-
|
|
36
|
-
/** @type {import('vite').Plugin} */
|
|
37
|
-
const sveltekit_plugin = {
|
|
38
|
-
name: 'vite-plugin-svelte-kit',
|
|
39
|
-
async config(vite_config) {
|
|
40
|
-
// defaults
|
|
41
|
-
vite_config.preview = vite_config.preview || {};
|
|
42
|
-
vite_config.preview.strictPort = vite_config.preview.strictPort ?? true;
|
|
43
|
-
|
|
44
|
-
config = await load_config();
|
|
45
|
-
},
|
|
46
|
-
async configResolved(vite_config) {
|
|
47
|
-
https = !!vite_config.preview.https;
|
|
48
|
-
},
|
|
49
|
-
async configurePreviewServer(vite) {
|
|
50
|
-
installPolyfills();
|
|
51
|
-
|
|
52
|
-
const { paths } = config.kit;
|
|
53
|
-
const base = paths.base;
|
|
54
|
-
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
55
|
-
|
|
56
|
-
const etag = `"${Date.now()}"`;
|
|
57
|
-
|
|
58
|
-
const index_file = join(config.kit.outDir, 'output/server/index.js');
|
|
59
|
-
const manifest_file = join(config.kit.outDir, 'output/server/manifest.js');
|
|
60
|
-
|
|
61
|
-
/** @type {import('types').ServerModule} */
|
|
62
|
-
const { Server, override } = await import(pathToFileURL(index_file).href);
|
|
63
|
-
const { manifest } = await import(pathToFileURL(manifest_file).href);
|
|
64
|
-
|
|
65
|
-
override({
|
|
66
|
-
paths: { base, assets },
|
|
67
|
-
prerendering: false,
|
|
68
|
-
protocol: https ? 'https' : 'http',
|
|
69
|
-
read: (file) => fs__default.readFileSync(join(config.kit.files.assets, file))
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const server = new Server(manifest);
|
|
73
|
-
|
|
74
|
-
return () => {
|
|
75
|
-
// files in `static`
|
|
76
|
-
vite.middlewares.use(scoped(assets, mutable(config.kit.files.assets)));
|
|
77
|
-
|
|
78
|
-
// immutable generated client assets
|
|
79
|
-
vite.middlewares.use(
|
|
80
|
-
scoped(
|
|
81
|
-
assets,
|
|
82
|
-
sirv(join(config.kit.outDir, 'output/client'), {
|
|
83
|
-
setHeaders: (res, pathname) => {
|
|
84
|
-
// only apply to build directory, not e.g. version.json
|
|
85
|
-
if (pathname.startsWith(`/${config.kit.appDir}/immutable`)) {
|
|
86
|
-
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
vite.middlewares.use((req, res, next) => {
|
|
94
|
-
const original_url = /** @type {string} */ (req.url);
|
|
95
|
-
const { pathname } = new URL(original_url, 'http://dummy');
|
|
96
|
-
|
|
97
|
-
if (pathname.startsWith(base)) {
|
|
98
|
-
next();
|
|
99
|
-
} else {
|
|
100
|
-
res.statusCode = 404;
|
|
101
|
-
res.end(`Not found (did you mean ${base + pathname}?)`);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// prerendered dependencies
|
|
106
|
-
vite.middlewares.use(
|
|
107
|
-
scoped(base, mutable(join(config.kit.outDir, 'output/prerendered/dependencies')))
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// prerendered pages (we can't just use sirv because we need to
|
|
111
|
-
// preserve the correct trailingSlash behaviour)
|
|
112
|
-
vite.middlewares.use(
|
|
113
|
-
scoped(base, (req, res, next) => {
|
|
114
|
-
let if_none_match_value = req.headers['if-none-match'];
|
|
115
|
-
|
|
116
|
-
if (if_none_match_value?.startsWith('W/"')) {
|
|
117
|
-
if_none_match_value = if_none_match_value.substring(2);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (if_none_match_value === etag) {
|
|
121
|
-
res.statusCode = 304;
|
|
122
|
-
res.end();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const { pathname } = new URL(/** @type {string} */ (req.url), 'http://dummy');
|
|
127
|
-
|
|
128
|
-
// only treat this as a page if it doesn't include an extension
|
|
129
|
-
if (pathname === '/' || /\/[^./]+\/?$/.test(pathname)) {
|
|
130
|
-
const file = join(
|
|
131
|
-
config.kit.outDir,
|
|
132
|
-
'output/prerendered/pages' +
|
|
133
|
-
pathname +
|
|
134
|
-
(pathname.endsWith('/') ? 'index.html' : '.html')
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
if (fs__default.existsSync(file)) {
|
|
138
|
-
res.writeHead(200, {
|
|
139
|
-
'content-type': 'text/html',
|
|
140
|
-
etag
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
fs__default.createReadStream(file).pipe(res);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
next();
|
|
149
|
-
})
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
// SSR
|
|
153
|
-
vite.middlewares.use(async (req, res) => {
|
|
154
|
-
const protocol = https ? 'https' : 'http';
|
|
155
|
-
const host = req.headers['host'];
|
|
156
|
-
|
|
157
|
-
let request;
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
request = await getRequest(`${protocol}://${host}`, req);
|
|
161
|
-
} catch (/** @type {any} */ err) {
|
|
162
|
-
res.statusCode = err.status || 400;
|
|
163
|
-
return res.end(err.reason || 'Invalid request body');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
setResponse(
|
|
167
|
-
res,
|
|
168
|
-
await server.respond(request, {
|
|
169
|
-
getClientAddress: () => {
|
|
170
|
-
const { remoteAddress } = req.socket;
|
|
171
|
-
if (remoteAddress) return remoteAddress;
|
|
172
|
-
throw new Error('Could not determine clientAddress');
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @param {string} dir
|
|
183
|
-
* @returns {Handler}
|
|
184
|
-
*/
|
|
185
|
-
const mutable = (dir) =>
|
|
186
|
-
fs__default.existsSync(dir)
|
|
187
|
-
? sirv(dir, {
|
|
188
|
-
etag: true,
|
|
189
|
-
maxAge: 0
|
|
190
|
-
})
|
|
191
|
-
: (req, res, next) => next();
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @param {string} scope
|
|
195
|
-
* @param {Handler} handler
|
|
196
|
-
* @returns {Handler}
|
|
197
|
-
*/
|
|
198
|
-
function scoped(scope, handler) {
|
|
199
|
-
if (scope === '') return handler;
|
|
200
|
-
|
|
201
|
-
return (req, res, next) => {
|
|
202
|
-
if (req.url?.startsWith(scope)) {
|
|
203
|
-
const original_url = req.url;
|
|
204
|
-
req.url = req.url.slice(scope.length);
|
|
205
|
-
handler(req, res, () => {
|
|
206
|
-
req.url = original_url;
|
|
207
|
-
next();
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
next();
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export { sveltekit_plugin };
|