@sveltejs/kit 1.0.0-next.36 → 1.0.0-next.362
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/README.md +12 -9
- package/assets/app/env.js +28 -0
- package/assets/app/navigation.js +24 -0
- package/assets/app/paths.js +1 -0
- package/assets/app/stores.js +97 -0
- package/assets/client/singletons.js +13 -0
- package/assets/client/start.js +1793 -0
- package/assets/components/error.svelte +18 -2
- package/assets/env.js +8 -0
- package/assets/paths.js +13 -0
- package/assets/server/index.js +3460 -0
- package/dist/chunks/_commonjsHelpers.js +3 -0
- package/dist/chunks/error.js +661 -0
- package/dist/chunks/index.js +15744 -0
- package/dist/chunks/index2.js +210 -0
- package/dist/chunks/multipart-parser.js +445 -0
- package/dist/chunks/sync.js +980 -0
- package/dist/chunks/write_tsconfig.js +274 -0
- package/dist/cli.js +64 -117
- package/dist/hooks.js +28 -0
- package/dist/node/polyfills.js +12237 -0
- package/dist/node.js +5855 -0
- package/dist/vite.js +3141 -0
- package/package.json +100 -55
- package/types/ambient.d.ts +345 -0
- package/types/index.d.ts +293 -0
- package/types/internal.d.ts +318 -0
- package/types/private.d.ts +235 -0
- package/CHANGELOG.md +0 -377
- package/assets/runtime/app/navigation.js +0 -23
- package/assets/runtime/app/navigation.js.map +0 -1
- package/assets/runtime/app/paths.js +0 -2
- package/assets/runtime/app/paths.js.map +0 -1
- package/assets/runtime/app/stores.js +0 -78
- package/assets/runtime/app/stores.js.map +0 -1
- package/assets/runtime/internal/singletons.js +0 -15
- package/assets/runtime/internal/singletons.js.map +0 -1
- package/assets/runtime/internal/start.js +0 -614
- package/assets/runtime/internal/start.js.map +0 -1
- package/assets/runtime/utils-85ebcc60.js +0 -18
- package/assets/runtime/utils-85ebcc60.js.map +0 -1
- package/dist/api.js +0 -28
- package/dist/api.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/create_app.js +0 -502
- package/dist/create_app.js.map +0 -1
- package/dist/index.js +0 -327
- package/dist/index.js.map +0 -1
- package/dist/index2.js +0 -3497
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -296
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -311
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -221
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -730
- package/dist/index6.js.map +0 -1
- package/dist/renderer.js +0 -2429
- package/dist/renderer.js.map +0 -1
- package/dist/standard.js +0 -100
- package/dist/standard.js.map +0 -1
- package/dist/utils.js +0 -61
- package/dist/utils.js.map +0 -1
package/dist/index3.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import fs, { writeFileSync, readFileSync } from 'fs';
|
|
2
|
-
import { resolve, relative } from 'path';
|
|
3
|
-
import { r as rimraf, c as copy_assets } from './utils.js';
|
|
4
|
-
import { c as create_manifest_data, a as create_app } from './create_app.js';
|
|
5
|
-
import vite from 'vite';
|
|
6
|
-
import svelte from '@sveltejs/vite-plugin-svelte';
|
|
7
|
-
import './index.js';
|
|
8
|
-
import 'url';
|
|
9
|
-
import './standard.js';
|
|
10
|
-
|
|
11
|
-
const s = JSON.stringify;
|
|
12
|
-
|
|
13
|
-
const build_dir = '.svelte/build';
|
|
14
|
-
const output_dir = '.svelte/output';
|
|
15
|
-
|
|
16
|
-
async function build(config) {
|
|
17
|
-
const manifest = create_manifest_data({
|
|
18
|
-
config,
|
|
19
|
-
output: build_dir
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
rimraf(build_dir);
|
|
23
|
-
|
|
24
|
-
create_app({
|
|
25
|
-
manifest_data: manifest,
|
|
26
|
-
output: build_dir
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
copy_assets(build_dir);
|
|
30
|
-
|
|
31
|
-
// prettier-ignore
|
|
32
|
-
writeFileSync(`${build_dir}/runtime/app/env.js`, [
|
|
33
|
-
'export const browser = !import.meta.env.SSR;',
|
|
34
|
-
'export const dev = false;',
|
|
35
|
-
`export const amp = ${config.amp};`
|
|
36
|
-
].join('\n'));
|
|
37
|
-
|
|
38
|
-
const client_entry_file = `${build_dir}/runtime/internal/start.js`;
|
|
39
|
-
const client_out_dir = `${output_dir}/client/${config.appDir}`;
|
|
40
|
-
const client_manifest_file = `${client_out_dir}/manifest.json`;
|
|
41
|
-
|
|
42
|
-
const base =
|
|
43
|
-
config.paths.assets === '/.'
|
|
44
|
-
? `/${config.appDir}/`
|
|
45
|
-
: `${config.paths.assets}/${config.appDir}/`;
|
|
46
|
-
|
|
47
|
-
// client build
|
|
48
|
-
await vite.build({
|
|
49
|
-
base,
|
|
50
|
-
build: {
|
|
51
|
-
cssCodeSplit: true,
|
|
52
|
-
manifest: true,
|
|
53
|
-
lib: {
|
|
54
|
-
entry: client_entry_file,
|
|
55
|
-
name: 'app',
|
|
56
|
-
formats: ['es']
|
|
57
|
-
},
|
|
58
|
-
outDir: client_out_dir
|
|
59
|
-
},
|
|
60
|
-
resolve: {
|
|
61
|
-
alias: {
|
|
62
|
-
$app: resolve(`${build_dir}/runtime/app`)
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
plugins: [
|
|
66
|
-
svelte({
|
|
67
|
-
emitCss: true,
|
|
68
|
-
compilerOptions: {
|
|
69
|
-
dev: true,
|
|
70
|
-
hydratable: true
|
|
71
|
-
},
|
|
72
|
-
hot: true
|
|
73
|
-
})
|
|
74
|
-
]
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const client_manifest = JSON.parse(readFileSync(client_manifest_file, 'utf-8'));
|
|
78
|
-
fs.unlinkSync(client_manifest_file);
|
|
79
|
-
|
|
80
|
-
let setup_file = 'src/setup/index.js';
|
|
81
|
-
if (!fs.existsSync(setup_file)) {
|
|
82
|
-
setup_file = `${build_dir}/setup.js`;
|
|
83
|
-
fs.writeFileSync(setup_file, '');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const app_file = `${build_dir}/app.js`;
|
|
87
|
-
const app_relative = (file) => {
|
|
88
|
-
const relative_file = relative(build_dir, file);
|
|
89
|
-
return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const component_indexes = new Map();
|
|
93
|
-
manifest.components.forEach((c, i) => {
|
|
94
|
-
component_indexes.set(c, i);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const stringify_component = (c) => `() => import(${s(`${app_relative(c)}`)})`;
|
|
98
|
-
|
|
99
|
-
// TODO ideally we wouldn't embed the css_lookup, but this is the easiest
|
|
100
|
-
// way to be able to inline CSS into AMP documents. if we come up with
|
|
101
|
-
// something better, we could use it for non-AMP documents too, as
|
|
102
|
-
// critical CSS below a certain threshold _should_ be inlined
|
|
103
|
-
const css_lookup = {};
|
|
104
|
-
// manifest.pages.forEach((data) => {
|
|
105
|
-
// data.parts.forEach((c) => {
|
|
106
|
-
// const deps = client.deps[c];
|
|
107
|
-
// deps.css.forEach((dep) => {
|
|
108
|
-
// const url = `${config.paths.assets}/${config.appDir}/${dep}`.replace(/^\/\./, '');
|
|
109
|
-
// const file = `${OPTIMIZED}/client/${config.appDir}/${dep}`;
|
|
110
|
-
|
|
111
|
-
// css_lookup[url] = readFileSync(file, 'utf-8');
|
|
112
|
-
// });
|
|
113
|
-
// });
|
|
114
|
-
// });
|
|
115
|
-
|
|
116
|
-
// TODO get_stack, below, just returns the stack as-is, without sourcemapping
|
|
117
|
-
|
|
118
|
-
const entry = `${config.paths.assets}/${config.appDir}/${client_manifest[client_entry_file].file}`;
|
|
119
|
-
|
|
120
|
-
// prettier-ignore
|
|
121
|
-
fs.writeFileSync(
|
|
122
|
-
app_file,
|
|
123
|
-
`
|
|
124
|
-
import * as renderer from '@sveltejs/kit/renderer';
|
|
125
|
-
import root from ${s(app_relative(`${build_dir}/generated/root.svelte`))};
|
|
126
|
-
import { set_paths } from ${s(app_relative(`${build_dir}/runtime/internal/singletons.js`))};
|
|
127
|
-
import * as setup from '${app_relative(setup_file)}';
|
|
128
|
-
|
|
129
|
-
const template = ({ head, body }) => ${s(fs.readFileSync(config.files.template, 'utf-8'))
|
|
130
|
-
.replace('%svelte.head%', '" + head + "')
|
|
131
|
-
.replace('%svelte.body%', '" + body + "')};
|
|
132
|
-
|
|
133
|
-
set_paths(${s(config.paths)});
|
|
134
|
-
|
|
135
|
-
// allow paths to be overridden in svelte-kit start
|
|
136
|
-
export function init({ paths }) {
|
|
137
|
-
set_paths(paths);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
init({ paths: ${s(config.paths)} });
|
|
141
|
-
|
|
142
|
-
const d = decodeURIComponent;
|
|
143
|
-
const empty = () => ({});
|
|
144
|
-
|
|
145
|
-
const components = [
|
|
146
|
-
${manifest.components.map((c) => stringify_component(c)).join(',\n\t\t\t\t')}
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
${config.amp ? `
|
|
150
|
-
const css_lookup = ${s(css_lookup)};` : ''}
|
|
151
|
-
|
|
152
|
-
const manifest = {
|
|
153
|
-
assets: ${s(manifest.assets)},
|
|
154
|
-
layout: ${stringify_component(manifest.layout)},
|
|
155
|
-
error: ${stringify_component(manifest.error)},
|
|
156
|
-
pages: [
|
|
157
|
-
${manifest.pages
|
|
158
|
-
.map((data) => {
|
|
159
|
-
const params = get_params(data.params);
|
|
160
|
-
const parts = data.parts.map(c => `components[${component_indexes.get(c)}]`);
|
|
161
|
-
|
|
162
|
-
const prefix = config.paths.assets === '/.' ? '' : config.paths.assets;
|
|
163
|
-
const path_to_dep = dep => prefix + `/${config.appDir}/${dep}`;
|
|
164
|
-
|
|
165
|
-
const js_deps = new Set();
|
|
166
|
-
const css_deps = new Set();
|
|
167
|
-
|
|
168
|
-
function find_deps(id) {
|
|
169
|
-
const chunk = client_manifest[id];
|
|
170
|
-
js_deps.add(path_to_dep(chunk.file));
|
|
171
|
-
|
|
172
|
-
if (chunk.css) {
|
|
173
|
-
chunk.css.forEach(file => css_deps.add(path_to_dep(file)));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (chunk.imports) {
|
|
177
|
-
chunk.imports.forEach(find_deps);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
for (const part of data.parts) {
|
|
182
|
-
find_deps(part);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// data.parts.forEach(c => {
|
|
186
|
-
// const deps = client.deps[c];
|
|
187
|
-
// deps.js.forEach(dep => js_deps.add(path_to_dep(dep)));
|
|
188
|
-
// deps.css.forEach(dep => css_deps.add(path_to_dep(dep)));
|
|
189
|
-
// });
|
|
190
|
-
|
|
191
|
-
return `{
|
|
192
|
-
pattern: ${data.pattern},
|
|
193
|
-
params: ${params},
|
|
194
|
-
parts: [${parts.join(', ')}],
|
|
195
|
-
css: [${Array.from(css_deps).map(s).join(', ')}],
|
|
196
|
-
js: [${Array.from(js_deps).map(s).join(', ')}]
|
|
197
|
-
}`;
|
|
198
|
-
})
|
|
199
|
-
.join(',\n\t\t\t\t\t')}
|
|
200
|
-
],
|
|
201
|
-
endpoints: [
|
|
202
|
-
${manifest.endpoints
|
|
203
|
-
.map((data) => {
|
|
204
|
-
const params = get_params(data.params);
|
|
205
|
-
const load = `() => import(${s(app_relative(data.file))})`;
|
|
206
|
-
|
|
207
|
-
return `{ pattern: ${data.pattern}, params: ${params}, load: ${load} }`;
|
|
208
|
-
})
|
|
209
|
-
.join(',\n\t\t\t\t\t')}
|
|
210
|
-
]
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export function render(request, {
|
|
214
|
-
paths = ${s(config.paths)},
|
|
215
|
-
local = false,
|
|
216
|
-
only_prerender = false,
|
|
217
|
-
get_static_file
|
|
218
|
-
} = {}) {
|
|
219
|
-
return renderer.render(request, {
|
|
220
|
-
paths,
|
|
221
|
-
local,
|
|
222
|
-
template,
|
|
223
|
-
manifest,
|
|
224
|
-
target: ${s(config.target)},${
|
|
225
|
-
config.startGlobal ? `\n\t\t\t\t\tstart_global: ${s(config.startGlobal)},` : ''
|
|
226
|
-
}
|
|
227
|
-
entry: ${s(entry)},
|
|
228
|
-
root,
|
|
229
|
-
setup,
|
|
230
|
-
dev: false,
|
|
231
|
-
amp: ${config.amp},
|
|
232
|
-
only_prerender,
|
|
233
|
-
app_dir: ${s(config.appDir)},
|
|
234
|
-
host: ${s(config.host)},
|
|
235
|
-
host_header: ${s(config.hostHeader)},
|
|
236
|
-
get_stack: error => error.stack,
|
|
237
|
-
get_static_file,
|
|
238
|
-
get_amp_css: dep => css_lookup[dep]
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
`
|
|
242
|
-
.replace(/^\t{3}/gm, '')
|
|
243
|
-
.trim()
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
await vite.build({
|
|
247
|
-
base,
|
|
248
|
-
build: {
|
|
249
|
-
ssr: true,
|
|
250
|
-
lib: {
|
|
251
|
-
entry: app_file,
|
|
252
|
-
name: 'app',
|
|
253
|
-
formats: ['es']
|
|
254
|
-
},
|
|
255
|
-
outDir: `${output_dir}/server`
|
|
256
|
-
},
|
|
257
|
-
resolve: {
|
|
258
|
-
alias: {
|
|
259
|
-
$app: resolve(`${build_dir}/runtime/app`)
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
plugins: [
|
|
263
|
-
svelte({
|
|
264
|
-
emitCss: true,
|
|
265
|
-
compilerOptions: {
|
|
266
|
-
dev: true,
|
|
267
|
-
hydratable: true
|
|
268
|
-
},
|
|
269
|
-
hot: true
|
|
270
|
-
})
|
|
271
|
-
],
|
|
272
|
-
ssr: {
|
|
273
|
-
noExternal: ['svelte']
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// given an array of params like `['x', 'y', 'z']` for
|
|
279
|
-
// src/routes/[x]/[y]/[z]/svelte, create a function
|
|
280
|
-
// that turns a RexExpMatchArray into ({ x, y, z })
|
|
281
|
-
function get_params(array) {
|
|
282
|
-
return array.length
|
|
283
|
-
? '(m) => ({ ' +
|
|
284
|
-
array
|
|
285
|
-
.map((param, i) => {
|
|
286
|
-
return param.startsWith('...')
|
|
287
|
-
? `${param.slice(3)}: d(m[${i + 1}]).split('/')`
|
|
288
|
-
: `${param}: d(m[${i + 1}])`;
|
|
289
|
-
})
|
|
290
|
-
.join(', ') +
|
|
291
|
-
'})'
|
|
292
|
-
: 'empty';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export { build };
|
|
296
|
-
//# sourceMappingURL=index3.js.map
|
package/dist/index3.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index3.js","sources":["../src/api/build/index.js"],"sourcesContent":["import fs, { readFileSync, writeFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport { rimraf } from '@sveltejs/app-utils/files';\nimport create_manifest_data from '../../core/create_manifest_data';\nimport { copy_assets } from '../utils';\nimport { create_app } from '../../core/create_app';\nimport vite from 'vite';\nimport svelte from '@sveltejs/vite-plugin-svelte';\n\nconst s = JSON.stringify;\n\nconst build_dir = '.svelte/build';\nconst output_dir = '.svelte/output';\n\nexport async function build(config) {\n\tconst manifest = create_manifest_data({\n\t\tconfig,\n\t\toutput: build_dir\n\t});\n\n\trimraf(build_dir);\n\n\tcreate_app({\n\t\tmanifest_data: manifest,\n\t\toutput: build_dir\n\t});\n\n\tcopy_assets(build_dir);\n\n\t// prettier-ignore\n\twriteFileSync(`${build_dir}/runtime/app/env.js`, [\n\t\t'export const browser = !import.meta.env.SSR;',\n\t\t'export const dev = false;',\n\t\t`export const amp = ${config.amp};`\n\t].join('\\n'));\n\n\tconst client_entry_file = `${build_dir}/runtime/internal/start.js`;\n\tconst client_out_dir = `${output_dir}/client/${config.appDir}`;\n\tconst client_manifest_file = `${client_out_dir}/manifest.json`;\n\n\tconst base =\n\t\tconfig.paths.assets === '/.'\n\t\t\t? `/${config.appDir}/`\n\t\t\t: `${config.paths.assets}/${config.appDir}/`;\n\n\t// client build\n\tawait vite.build({\n\t\tbase,\n\t\tbuild: {\n\t\t\tcssCodeSplit: true,\n\t\t\tmanifest: true,\n\t\t\tlib: {\n\t\t\t\tentry: client_entry_file,\n\t\t\t\tname: 'app',\n\t\t\t\tformats: ['es']\n\t\t\t},\n\t\t\toutDir: client_out_dir\n\t\t},\n\t\tresolve: {\n\t\t\talias: {\n\t\t\t\t$app: resolve(`${build_dir}/runtime/app`)\n\t\t\t}\n\t\t},\n\t\tplugins: [\n\t\t\tsvelte({\n\t\t\t\temitCss: true,\n\t\t\t\tcompilerOptions: {\n\t\t\t\t\tdev: true,\n\t\t\t\t\thydratable: true\n\t\t\t\t},\n\t\t\t\thot: true\n\t\t\t})\n\t\t]\n\t});\n\n\tconst client_manifest = JSON.parse(readFileSync(client_manifest_file, 'utf-8'));\n\tfs.unlinkSync(client_manifest_file);\n\n\tlet setup_file = 'src/setup/index.js';\n\tif (!fs.existsSync(setup_file)) {\n\t\tsetup_file = `${build_dir}/setup.js`;\n\t\tfs.writeFileSync(setup_file, '');\n\t}\n\n\tconst app_file = `${build_dir}/app.js`;\n\tconst app_relative = (file) => {\n\t\tconst relative_file = relative(build_dir, file);\n\t\treturn relative_file[0] === '.' ? relative_file : `./${relative_file}`;\n\t};\n\n\tconst component_indexes = new Map();\n\tmanifest.components.forEach((c, i) => {\n\t\tcomponent_indexes.set(c, i);\n\t});\n\n\tconst stringify_component = (c) => `() => import(${s(`${app_relative(c)}`)})`;\n\n\t// TODO ideally we wouldn't embed the css_lookup, but this is the easiest\n\t// way to be able to inline CSS into AMP documents. if we come up with\n\t// something better, we could use it for non-AMP documents too, as\n\t// critical CSS below a certain threshold _should_ be inlined\n\tconst css_lookup = {};\n\t// manifest.pages.forEach((data) => {\n\t// \tdata.parts.forEach((c) => {\n\t// \t\tconst deps = client.deps[c];\n\t// \t\tdeps.css.forEach((dep) => {\n\t// \t\t\tconst url = `${config.paths.assets}/${config.appDir}/${dep}`.replace(/^\\/\\./, '');\n\t// \t\t\tconst file = `${OPTIMIZED}/client/${config.appDir}/${dep}`;\n\n\t// \t\t\tcss_lookup[url] = readFileSync(file, 'utf-8');\n\t// \t\t});\n\t// \t});\n\t// });\n\n\t// TODO get_stack, below, just returns the stack as-is, without sourcemapping\n\n\tconst entry = `${config.paths.assets}/${config.appDir}/${client_manifest[client_entry_file].file}`;\n\n\t// prettier-ignore\n\tfs.writeFileSync(\n\t\tapp_file,\n\t\t`\n\t\t\timport * as renderer from '@sveltejs/kit/renderer';\n\t\t\timport root from ${s(app_relative(`${build_dir}/generated/root.svelte`))};\n\t\t\timport { set_paths } from ${s(app_relative(`${build_dir}/runtime/internal/singletons.js`))};\n\t\t\timport * as setup from '${app_relative(setup_file)}';\n\n\t\t\tconst template = ({ head, body }) => ${s(fs.readFileSync(config.files.template, 'utf-8'))\n\t\t\t\t.replace('%svelte.head%', '\" + head + \"')\n\t\t\t\t.replace('%svelte.body%', '\" + body + \"')};\n\n\t\t\tset_paths(${s(config.paths)});\n\n\t\t\t// allow paths to be overridden in svelte-kit start\n\t\t\texport function init({ paths }) {\n\t\t\t\tset_paths(paths);\n\t\t\t}\n\n\t\t\tinit({ paths: ${s(config.paths)} });\n\n\t\t\tconst d = decodeURIComponent;\n\t\t\tconst empty = () => ({});\n\n\t\t\tconst components = [\n\t\t\t\t${manifest.components.map((c) => stringify_component(c)).join(',\\n\\t\\t\\t\\t')}\n\t\t\t];\n\n\t\t\t${config.amp ? `\n\t\t\tconst css_lookup = ${s(css_lookup)};` : ''}\n\n\t\t\tconst manifest = {\n\t\t\t\tassets: ${s(manifest.assets)},\n\t\t\t\tlayout: ${stringify_component(manifest.layout)},\n\t\t\t\terror: ${stringify_component(manifest.error)},\n\t\t\t\tpages: [\n\t\t\t\t\t${manifest.pages\n\t\t\t\t\t\t.map((data) => {\n\t\t\t\t\t\t\tconst params = get_params(data.params);\n\t\t\t\t\t\t\tconst parts = data.parts.map(c => `components[${component_indexes.get(c)}]`);\n\n\t\t\t\t\t\t\tconst prefix = config.paths.assets === '/.' ? '' : config.paths.assets;\n\t\t\t\t\t\t\tconst path_to_dep = dep => prefix + `/${config.appDir}/${dep}`;\n\n\t\t\t\t\t\t\tconst js_deps = new Set();\n\t\t\t\t\t\t\tconst css_deps = new Set();\n\n\t\t\t\t\t\t\tfunction find_deps(id) {\n\t\t\t\t\t\t\t\tconst chunk = client_manifest[id];\n\t\t\t\t\t\t\t\tjs_deps.add(path_to_dep(chunk.file));\n\n\t\t\t\t\t\t\t\tif (chunk.css) {\n\t\t\t\t\t\t\t\t\tchunk.css.forEach(file => css_deps.add(path_to_dep(file)));\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (chunk.imports) {\n\t\t\t\t\t\t\t\t\tchunk.imports.forEach(find_deps);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfor (const part of data.parts) {\n\t\t\t\t\t\t\t\tfind_deps(part);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// data.parts.forEach(c => {\n\t\t\t\t\t\t\t// \tconst deps = client.deps[c];\n\t\t\t\t\t\t\t// \tdeps.js.forEach(dep => js_deps.add(path_to_dep(dep)));\n\t\t\t\t\t\t\t// \tdeps.css.forEach(dep => css_deps.add(path_to_dep(dep)));\n\t\t\t\t\t\t\t// });\n\n\t\t\t\t\t\t\treturn `{\n\t\t\t\t\t\t\t\tpattern: ${data.pattern},\n\t\t\t\t\t\t\t\tparams: ${params},\n\t\t\t\t\t\t\t\tparts: [${parts.join(', ')}],\n\t\t\t\t\t\t\t\tcss: [${Array.from(css_deps).map(s).join(', ')}],\n\t\t\t\t\t\t\t\tjs: [${Array.from(js_deps).map(s).join(', ')}]\n\t\t\t\t\t\t\t}`;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join(',\\n\\t\\t\\t\\t\\t')}\n\t\t\t\t],\n\t\t\t\tendpoints: [\n\t\t\t\t\t${manifest.endpoints\n\t\t\t\t\t\t.map((data) => {\n\t\t\t\t\t\t\tconst params = get_params(data.params);\n\t\t\t\t\t\t\tconst load = `() => import(${s(app_relative(data.file))})`;\n\n\t\t\t\t\t\t\treturn `{ pattern: ${data.pattern}, params: ${params}, load: ${load} }`;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join(',\\n\\t\\t\\t\\t\\t')}\n\t\t\t\t]\n\t\t\t};\n\n\t\t\texport function render(request, {\n\t\t\t\tpaths = ${s(config.paths)},\n\t\t\t\tlocal = false,\n\t\t\t\tonly_prerender = false,\n\t\t\t\tget_static_file\n\t\t\t} = {}) {\n\t\t\t\treturn renderer.render(request, {\n\t\t\t\t\tpaths,\n\t\t\t\t\tlocal,\n\t\t\t\t\ttemplate,\n\t\t\t\t\tmanifest,\n\t\t\t\t\ttarget: ${s(config.target)},${\n\t\t\t\t\t\tconfig.startGlobal ? `\\n\\t\\t\\t\\t\\tstart_global: ${s(config.startGlobal)},` : ''\n\t\t\t\t\t}\n\t\t\t\t\tentry: ${s(entry)},\n\t\t\t\t\troot,\n\t\t\t\t\tsetup,\n\t\t\t\t\tdev: false,\n\t\t\t\t\tamp: ${config.amp},\n\t\t\t\t\tonly_prerender,\n\t\t\t\t\tapp_dir: ${s(config.appDir)},\n\t\t\t\t\thost: ${s(config.host)},\n\t\t\t\t\thost_header: ${s(config.hostHeader)},\n\t\t\t\t\tget_stack: error => error.stack,\n\t\t\t\t\tget_static_file,\n\t\t\t\t\tget_amp_css: dep => css_lookup[dep]\n\t\t\t\t});\n\t\t\t}\n\t\t`\n\t\t\t.replace(/^\\t{3}/gm, '')\n\t\t\t.trim()\n\t);\n\n\tawait vite.build({\n\t\tbase,\n\t\tbuild: {\n\t\t\tssr: true,\n\t\t\tlib: {\n\t\t\t\tentry: app_file,\n\t\t\t\tname: 'app',\n\t\t\t\tformats: ['es']\n\t\t\t},\n\t\t\toutDir: `${output_dir}/server`\n\t\t},\n\t\tresolve: {\n\t\t\talias: {\n\t\t\t\t$app: resolve(`${build_dir}/runtime/app`)\n\t\t\t}\n\t\t},\n\t\tplugins: [\n\t\t\tsvelte({\n\t\t\t\temitCss: true,\n\t\t\t\tcompilerOptions: {\n\t\t\t\t\tdev: true,\n\t\t\t\t\thydratable: true\n\t\t\t\t},\n\t\t\t\thot: true\n\t\t\t})\n\t\t],\n\t\tssr: {\n\t\t\tnoExternal: ['svelte']\n\t\t}\n\t});\n}\n\n// given an array of params like `['x', 'y', 'z']` for\n// src/routes/[x]/[y]/[z]/svelte, create a function\n// that turns a RexExpMatchArray into ({ x, y, z })\nfunction get_params(array) {\n\treturn array.length\n\t\t? '(m) => ({ ' +\n\t\t\t\tarray\n\t\t\t\t\t.map((param, i) => {\n\t\t\t\t\t\treturn param.startsWith('...')\n\t\t\t\t\t\t\t? `${param.slice(3)}: d(m[${i + 1}]).split('/')`\n\t\t\t\t\t\t\t: `${param}: d(m[${i + 1}])`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(', ') +\n\t\t\t\t'})'\n\t\t: 'empty';\n}\n"],"names":[],"mappings":";;;;;;;;;;AASA,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;AACzB;AACA,MAAM,SAAS,GAAG,eAAe,CAAC;AAClC,MAAM,UAAU,GAAG,gBAAgB,CAAC;AACpC;AACO,eAAe,KAAK,CAAC,MAAM,EAAE;AACpC,CAAC,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AACvC,EAAE,MAAM;AACR,EAAE,MAAM,EAAE,SAAS;AACnB,EAAE,CAAC,CAAC;AACJ;AACA,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACnB;AACA,CAAC,UAAU,CAAC;AACZ,EAAE,aAAa,EAAE,QAAQ;AACzB,EAAE,MAAM,EAAE,SAAS;AACnB,EAAE,CAAC,CAAC;AACJ;AACA,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;AACxB;AACA;AACA,CAAC,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;AAClD,EAAE,8CAA8C;AAChD,EAAE,2BAA2B;AAC7B,EAAE,CAAC,mBAAm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;AACJ,GAAG,MAAM,EAAE,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC;AACjC,GAAG;AACH,EAAE,OAAO,EAAE;AACX,GAAG,KAAK,EAAE;AACV,IAAI,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;AAC7C,IAAI;AACJ,GAAG;AACH,EAAE,OAAO,EAAE;AACX,GAAG,MAAM,CAAC;AACV,IAAI,OAAO,EAAE,IAAI;AACjB,IAAI,eAAe,EAAE;AACrB,KAAK,GAAG,EAAE,IAAI;AACd,KAAK,UAAU,EAAE,IAAI;AACrB,KAAK;AACL,IAAI,GAAG,EAAE,IAAI;AACb,IAAI,CAAC;AACL,GAAG;AACH,EAAE,GAAG,EAAE;AACP,GAAG,UAAU,EAAE,CAAC,QAAQ,CAAC;AACzB,GAAG;AACH,EAAE,CAAC,CAAC;AACJ,CAAC;AACD;AACA;AACA;AACA;AACA,SAAS,UAAU,CAAC,KAAK,EAAE;AAC3B,CAAC,OAAO,KAAK,CAAC,MAAM;AACpB,IAAI,YAAY;AAChB,IAAI,KAAK;AACT,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK;AACxB,MAAM,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC;AACpC,SAAS,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;AACvD,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;AACpC,MAAM,CAAC;AACP,MAAM,IAAI,CAAC,IAAI,CAAC;AAChB,IAAI,IAAI;AACR,IAAI,OAAO,CAAC;AACZ;;;;"}
|
package/dist/index4.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { readdirSync, statSync, existsSync, createReadStream, readFileSync } from 'fs';
|
|
2
|
-
import { createServer } from 'http';
|
|
3
|
-
import { parse as parse$1, URLSearchParams } from 'url';
|
|
4
|
-
import { resolve, join, normalize } from 'path';
|
|
5
|
-
import { M as Mime_1, s as standard } from './standard.js';
|
|
6
|
-
import { g as get_body } from './index5.js';
|
|
7
|
-
|
|
8
|
-
function list(dir, callback, pre='') {
|
|
9
|
-
dir = resolve('.', dir);
|
|
10
|
-
let arr = readdirSync(dir);
|
|
11
|
-
let i=0, abs, stats;
|
|
12
|
-
for (; i < arr.length; i++) {
|
|
13
|
-
abs = join(dir, arr[i]);
|
|
14
|
-
stats = statSync(abs);
|
|
15
|
-
stats.isDirectory()
|
|
16
|
-
? list(abs, callback, join(pre, arr[i]))
|
|
17
|
-
: callback(join(pre, arr[i]), abs, stats);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function parse(str) {
|
|
22
|
-
let i=0, j=0, k, v;
|
|
23
|
-
let out={}, arr=str.split('&');
|
|
24
|
-
for (; i < arr.length; i++) {
|
|
25
|
-
j = arr[i].indexOf('=');
|
|
26
|
-
v = !!~j && arr[i].substring(j+1) || '';
|
|
27
|
-
k = !!~j ? arr[i].substring(0, j) : arr[i];
|
|
28
|
-
out[k] = out[k] !== void 0 ? [].concat(out[k], v) : v;
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function parser (req, toDecode) {
|
|
34
|
-
let url = req.url;
|
|
35
|
-
if (url == null) return;
|
|
36
|
-
|
|
37
|
-
let obj = req._parsedUrl;
|
|
38
|
-
if (obj && obj._raw === url) return obj;
|
|
39
|
-
|
|
40
|
-
obj = {
|
|
41
|
-
path: url,
|
|
42
|
-
pathname: url,
|
|
43
|
-
search: null,
|
|
44
|
-
query: null,
|
|
45
|
-
href: url,
|
|
46
|
-
_raw: url
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
if (url.length > 1) {
|
|
50
|
-
if (toDecode && !req._decoded && !!~url.indexOf('%', 1)) {
|
|
51
|
-
let nxt = url;
|
|
52
|
-
try { nxt = decodeURIComponent(url); } catch (e) {/* bad */}
|
|
53
|
-
url = req.url = obj.href = obj.path = obj.pathname = obj._raw = nxt;
|
|
54
|
-
req._decoded = true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let idx = url.indexOf('?', 1);
|
|
58
|
-
|
|
59
|
-
if (idx !== -1) {
|
|
60
|
-
obj.search = url.substring(idx);
|
|
61
|
-
obj.query = obj.search.substring(1);
|
|
62
|
-
obj.pathname = url.substring(0, idx);
|
|
63
|
-
if (toDecode && obj.query.length > 0) {
|
|
64
|
-
obj.query = parse(obj.query);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (req._parsedUrl = obj);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
var lite = new Mime_1(standard);
|
|
73
|
-
|
|
74
|
-
const noop = () => {};
|
|
75
|
-
|
|
76
|
-
function isMatch(uri, arr) {
|
|
77
|
-
for (let i=0; i < arr.length; i++) {
|
|
78
|
-
if (arr[i].test(uri)) return true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function toAssume(uri, extns) {
|
|
83
|
-
let i=0, x, len=uri.length - 1;
|
|
84
|
-
if (uri.charCodeAt(len) === 47) {
|
|
85
|
-
uri = uri.substring(0, len);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let arr=[], tmp=`${uri}/index`;
|
|
89
|
-
for (; i < extns.length; i++) {
|
|
90
|
-
x = extns[i] ? `.${extns[i]}` : '';
|
|
91
|
-
if (uri) arr.push(uri + x);
|
|
92
|
-
arr.push(tmp + x);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return arr;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function viaCache(cache, uri, extns) {
|
|
99
|
-
let i=0, data, arr=toAssume(uri, extns);
|
|
100
|
-
for (; i < arr.length; i++) {
|
|
101
|
-
if (data = cache[arr[i]]) return data;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function viaLocal(dir, isEtag, uri, extns) {
|
|
106
|
-
let i=0, arr=toAssume(uri, extns);
|
|
107
|
-
let abs, stats, name, headers;
|
|
108
|
-
for (; i < arr.length; i++) {
|
|
109
|
-
abs = normalize(join(dir, name=arr[i]));
|
|
110
|
-
if (abs.startsWith(dir) && existsSync(abs)) {
|
|
111
|
-
stats = statSync(abs);
|
|
112
|
-
if (stats.isDirectory()) continue;
|
|
113
|
-
headers = toHeaders(name, stats, isEtag);
|
|
114
|
-
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
|
|
115
|
-
return { abs, stats, headers };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function is404(req, res) {
|
|
121
|
-
return (res.statusCode=404,res.end());
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function send(req, res, file, stats, headers) {
|
|
125
|
-
let code=200, tmp, opts={};
|
|
126
|
-
headers = { ...headers };
|
|
127
|
-
|
|
128
|
-
for (let key in headers) {
|
|
129
|
-
tmp = res.getHeader(key);
|
|
130
|
-
if (tmp) headers[key] = tmp;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (tmp = res.getHeader('content-type')) {
|
|
134
|
-
headers['Content-Type'] = tmp;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (req.headers.range) {
|
|
138
|
-
code = 206;
|
|
139
|
-
let [x, y] = req.headers.range.replace('bytes=', '').split('-');
|
|
140
|
-
let end = opts.end = parseInt(y, 10) || stats.size - 1;
|
|
141
|
-
let start = opts.start = parseInt(x, 10) || 0;
|
|
142
|
-
|
|
143
|
-
if (start >= stats.size || end >= stats.size) {
|
|
144
|
-
res.setHeader('Content-Range', `bytes */${stats.size}`);
|
|
145
|
-
res.statusCode = 416;
|
|
146
|
-
return res.end();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
|
|
150
|
-
headers['Content-Length'] = (end - start + 1);
|
|
151
|
-
headers['Accept-Ranges'] = 'bytes';
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
res.writeHead(code, headers);
|
|
155
|
-
createReadStream(file, opts).pipe(res);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function isEncoding(name, type, headers) {
|
|
159
|
-
headers['Content-Encoding'] = type;
|
|
160
|
-
headers['Content-Type'] = lite.getType(name.replace(/\.([^.]*)$/, '')) || '';
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function toHeaders(name, stats, isEtag) {
|
|
164
|
-
let headers = {
|
|
165
|
-
'Content-Length': stats.size,
|
|
166
|
-
'Content-Type': lite.getType(name) || '',
|
|
167
|
-
'Last-Modified': stats.mtime.toUTCString(),
|
|
168
|
-
};
|
|
169
|
-
if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
|
|
170
|
-
if (/\.br$/.test(name)) isEncoding(name, 'br', headers);
|
|
171
|
-
if (/\.gz$/.test(name)) isEncoding(name, 'gzip', headers);
|
|
172
|
-
return headers;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function sirv (dir, opts={}) {
|
|
176
|
-
dir = resolve(dir || '.');
|
|
177
|
-
|
|
178
|
-
let isNotFound = opts.onNoMatch || is404;
|
|
179
|
-
let setHeaders = opts.setHeaders || noop;
|
|
180
|
-
|
|
181
|
-
let extensions = opts.extensions || ['html', 'htm'];
|
|
182
|
-
let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
|
|
183
|
-
let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
|
|
184
|
-
|
|
185
|
-
const FILES = {};
|
|
186
|
-
|
|
187
|
-
let fallback = '/';
|
|
188
|
-
let isEtag = !!opts.etag;
|
|
189
|
-
let isSPA = !!opts.single;
|
|
190
|
-
if (typeof opts.single === 'string') {
|
|
191
|
-
let idx = opts.single.lastIndexOf('.');
|
|
192
|
-
fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
let ignores = [];
|
|
196
|
-
if (opts.ignores !== false) {
|
|
197
|
-
ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
|
|
198
|
-
if (opts.dotfiles) ignores.push(/\/\.\w/);
|
|
199
|
-
else ignores.push(/\/\.well-known/);
|
|
200
|
-
[].concat(opts.ignores || []).forEach(x => {
|
|
201
|
-
ignores.push(new RegExp(x, 'i'));
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
|
|
206
|
-
if (cc && opts.immutable) cc += ',immutable';
|
|
207
|
-
else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
|
|
208
|
-
|
|
209
|
-
if (!opts.dev) {
|
|
210
|
-
list(dir, (name, abs, stats) => {
|
|
211
|
-
if (/\.well-known[\\+\/]/.test(name)) ; // keep
|
|
212
|
-
else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
|
|
213
|
-
|
|
214
|
-
let headers = toHeaders(name, stats, isEtag);
|
|
215
|
-
if (cc) headers['Cache-Control'] = cc;
|
|
216
|
-
|
|
217
|
-
FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
let lookup = opts.dev ? viaLocal.bind(0, dir, isEtag) : viaCache.bind(0, FILES);
|
|
222
|
-
|
|
223
|
-
return function (req, res, next) {
|
|
224
|
-
let extns = [''];
|
|
225
|
-
let val = req.headers['accept-encoding'] || '';
|
|
226
|
-
if (gzips && val.includes('gzip')) extns.unshift(...gzips);
|
|
227
|
-
if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
|
|
228
|
-
extns.push(...extensions); // [...br, ...gz, orig, ...exts]
|
|
229
|
-
|
|
230
|
-
let pathname = req.path || parser(req, true).pathname;
|
|
231
|
-
let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
|
|
232
|
-
if (!data) return next ? next() : isNotFound(req, res);
|
|
233
|
-
|
|
234
|
-
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
|
|
235
|
-
res.writeHead(304);
|
|
236
|
-
return res.end();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (gzips || brots) {
|
|
240
|
-
res.setHeader('Vary', 'Accept-Encoding');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
setHeaders(res, pathname, data.stats);
|
|
244
|
-
send(req, res, data.abs, data.stats, data.headers);
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const mutable = (dir) =>
|
|
249
|
-
sirv(dir, {
|
|
250
|
-
etag: true,
|
|
251
|
-
maxAge: 0
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
async function start({ port, config }) {
|
|
255
|
-
const app_file = resolve('.svelte/output/server/app.js');
|
|
256
|
-
const app = await import(app_file);
|
|
257
|
-
|
|
258
|
-
const static_handler = existsSync(config.files.assets)
|
|
259
|
-
? mutable(config.files.assets)
|
|
260
|
-
: (_req, _res, next) => next();
|
|
261
|
-
|
|
262
|
-
const assets_handler = sirv('.svelte/output/client', {
|
|
263
|
-
maxAge: 31536000,
|
|
264
|
-
immutable: true
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return new Promise((fulfil) => {
|
|
268
|
-
const server = createServer((req, res) => {
|
|
269
|
-
const parsed = parse$1(req.url || '');
|
|
270
|
-
|
|
271
|
-
assets_handler(req, res, () => {
|
|
272
|
-
static_handler(req, res, async () => {
|
|
273
|
-
const rendered = await app.render(
|
|
274
|
-
{
|
|
275
|
-
method: req.method,
|
|
276
|
-
headers: req.headers,
|
|
277
|
-
path: parsed.pathname,
|
|
278
|
-
body: await get_body(req),
|
|
279
|
-
query: new URLSearchParams(parsed.query || '')
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
paths: {
|
|
283
|
-
base: '',
|
|
284
|
-
assets: '/.'
|
|
285
|
-
},
|
|
286
|
-
get_stack: (error) => error.stack, // TODO should this return a sourcemapped stacktrace?
|
|
287
|
-
get_static_file: (file) => readFileSync(join(config.files.assets, file))
|
|
288
|
-
}
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
if (rendered) {
|
|
292
|
-
res.writeHead(rendered.status, rendered.headers);
|
|
293
|
-
res.end(rendered.body);
|
|
294
|
-
} else {
|
|
295
|
-
res.statusCode = 404;
|
|
296
|
-
res.end('Not found');
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
server.listen(port, () => {
|
|
303
|
-
fulfil(server);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
return server;
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export { start };
|
|
311
|
-
//# sourceMappingURL=index4.js.map
|