screenreader-speech-capture 0.0.1-preview.5 → 0.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/README.md +20 -0
- package/dist/cli.mjs +3876 -939
- package/dist/ui/adapter-node.js +11 -0
- package/dist/ui/client/_app/immutable/chunks/BMrJcSB7.js +3 -0
- package/dist/ui/client/_app/immutable/chunks/BMrJcSB7.js.br +0 -0
- package/dist/ui/client/_app/immutable/chunks/BMrJcSB7.js.gz +0 -0
- package/dist/ui/client/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/dist/ui/client/_app/immutable/chunks/Bjy-W4x2.js.br +0 -0
- package/dist/ui/client/_app/immutable/chunks/Bjy-W4x2.js.gz +0 -0
- package/dist/ui/client/_app/immutable/chunks/BueZJg5y.js +2 -0
- package/dist/ui/client/_app/immutable/chunks/BueZJg5y.js.br +0 -0
- package/dist/ui/client/_app/immutable/chunks/BueZJg5y.js.gz +0 -0
- package/dist/ui/client/_app/immutable/chunks/DclECHGd.js +1 -0
- package/dist/ui/client/_app/immutable/chunks/DclECHGd.js.br +0 -0
- package/dist/ui/client/_app/immutable/chunks/DclECHGd.js.gz +0 -0
- package/dist/ui/client/_app/immutable/chunks/ZzrMKdp0.js +1 -0
- package/dist/ui/client/_app/immutable/chunks/ZzrMKdp0.js.br +0 -0
- package/dist/ui/client/_app/immutable/chunks/ZzrMKdp0.js.gz +0 -0
- package/dist/ui/client/_app/immutable/entry/app.BGREpuCm.js +2 -0
- package/dist/ui/client/_app/immutable/entry/app.BGREpuCm.js.br +0 -0
- package/dist/ui/client/_app/immutable/entry/app.BGREpuCm.js.gz +0 -0
- package/dist/ui/client/_app/immutable/entry/payload.DSmR2FwN.js +1 -0
- package/dist/ui/client/_app/immutable/entry/payload.DSmR2FwN.js.br +0 -0
- package/dist/ui/client/_app/immutable/entry/payload.DSmR2FwN.js.gz +0 -0
- package/dist/ui/client/_app/immutable/entry/start.Bj3y6VYi.js +2 -0
- package/dist/ui/client/_app/immutable/entry/start.Bj3y6VYi.js.br +0 -0
- package/dist/ui/client/_app/immutable/entry/start.Bj3y6VYi.js.gz +0 -0
- package/dist/ui/client/_app/immutable/nodes/0.BdmtdjrF.js +1 -0
- package/dist/ui/client/_app/immutable/nodes/0.BdmtdjrF.js.br +0 -0
- package/dist/ui/client/_app/immutable/nodes/0.BdmtdjrF.js.gz +0 -0
- package/dist/ui/client/_app/immutable/nodes/1.B76I_t5U.js +1 -0
- package/dist/ui/client/_app/immutable/nodes/1.B76I_t5U.js.br +0 -0
- package/dist/ui/client/_app/immutable/nodes/1.B76I_t5U.js.gz +0 -0
- package/dist/ui/client/_app/immutable/nodes/2.CpNTEXmI.js +1 -0
- package/dist/ui/client/_app/immutable/nodes/2.CpNTEXmI.js.br +0 -0
- package/dist/ui/client/_app/immutable/nodes/2.CpNTEXmI.js.gz +0 -0
- package/dist/ui/client/_app/version.json +1 -0
- package/dist/ui/client/_app/version.json.br +0 -0
- package/dist/ui/client/_app/version.json.gz +0 -0
- package/dist/ui/client/robots.txt +3 -0
- package/dist/ui/client/robots.txt.br +0 -0
- package/dist/ui/client/robots.txt.gz +0 -0
- package/dist/ui/handler.js +1 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/server/.vite/manifest.json +186 -0
- package/dist/ui/server/adapter-env.js +1 -0
- package/dist/ui/server/adapter-index.js +73 -0
- package/dist/ui/server/adapter-index.js.map +1 -0
- package/dist/ui/server/adapter-node-env.js +63 -0
- package/dist/ui/server/adapter-node-env.js.map +1 -0
- package/dist/ui/server/adapter-node-handler.js +616 -0
- package/dist/ui/server/adapter-node-handler.js.map +1 -0
- package/dist/ui/server/chunks/config.js +9 -0
- package/dist/ui/server/chunks/config.js.map +1 -0
- package/dist/ui/server/chunks/exports.js +484 -0
- package/dist/ui/server/chunks/exports.js.map +1 -0
- package/dist/ui/server/chunks/functions.js +29 -0
- package/dist/ui/server/chunks/functions.js.map +1 -0
- package/dist/ui/server/chunks/instance.js +3568 -0
- package/dist/ui/server/chunks/instance.js.map +1 -0
- package/dist/ui/server/chunks/internal.js +2900 -0
- package/dist/ui/server/chunks/internal.js.map +1 -0
- package/dist/ui/server/chunks/server-errors.js +487 -0
- package/dist/ui/server/chunks/server-errors.js.map +1 -0
- package/dist/ui/server/chunks/server.js +8 -0
- package/dist/ui/server/chunks/server.js.map +1 -0
- package/dist/ui/server/chunks/server2.js +1368 -0
- package/dist/ui/server/chunks/server2.js.map +1 -0
- package/dist/ui/server/chunks/shared.js +85 -0
- package/dist/ui/server/chunks/shared.js.map +1 -0
- package/dist/ui/server/chunks/uneval.js +534 -0
- package/dist/ui/server/chunks/uneval.js.map +1 -0
- package/dist/ui/server/entries/fallbacks/error.svelte.js +44 -0
- package/dist/ui/server/entries/fallbacks/error.svelte.js.map +1 -0
- package/dist/ui/server/entries/pages/_layout.server.ts.js +987 -0
- package/dist/ui/server/entries/pages/_layout.server.ts.js.map +1 -0
- package/dist/ui/server/entries/pages/_layout.svelte.js +15 -0
- package/dist/ui/server/entries/pages/_layout.svelte.js.map +1 -0
- package/dist/ui/server/entries/pages/_page.svelte.js +11 -0
- package/dist/ui/server/entries/pages/_page.svelte.js.map +1 -0
- package/dist/ui/server/env.js +1 -0
- package/dist/ui/server/handler.js +1 -0
- package/dist/ui/server/index.js +67 -0
- package/dist/ui/server/index.js.map +1 -0
- package/dist/ui/server/manifest-full.js +37 -0
- package/dist/ui/server/manifest.js +37 -0
- package/dist/ui/server/nodes/0.js +10 -0
- package/dist/ui/server/nodes/1.js +8 -0
- package/dist/ui/server/nodes/2.js +8 -0
- package/dist/ui/server/remote-entry.js +1565 -0
- package/dist/ui/server/remote-entry.js.map +1 -0
- package/dist/ui/server/server.js +39 -0
- package/package.json +18 -2
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import { a as SvelteKitError } from "./chunks/shared.js";
|
|
2
|
+
import { n as noop } from "./chunks/functions.js";
|
|
3
|
+
import { t as env } from "./adapter-node-env.js";
|
|
4
|
+
import fs, { createReadStream } from "node:fs";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { Readable, pipeline } from "node:stream";
|
|
7
|
+
import { app_path, assets, base, dir, env_prefix, mime_types, origin, prerendered_assets, server } from "../adapter-node.js";
|
|
8
|
+
import { format } from "node:url";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
// ../../node_modules/.pnpm/@sveltejs+kit@3.2.0_@sveltejs+vite-plugin-svelte@7.3.1_svelte@5.57.3_@typescript-eslint_ccfe35d88efff66f949c986fae0769d3/node_modules/@sveltejs/kit/src/exports/node/index.js
|
|
11
|
+
/** @type {WeakMap<import('http').IncomingMessage, (chunk: Buffer) => void>} */
|
|
12
|
+
var body_data_listeners = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
/**
|
|
14
|
+
* @param {import('http').IncomingMessage} req
|
|
15
|
+
* @param {number} [body_size_limit]
|
|
16
|
+
*/
|
|
17
|
+
function get_raw_body(req, body_size_limit) {
|
|
18
|
+
const h = req.headers;
|
|
19
|
+
const content_length = Number(h["content-length"]);
|
|
20
|
+
const has_content_length = Number.isFinite(content_length);
|
|
21
|
+
if (req.httpVersionMajor === 1 && !has_content_length && h["transfer-encoding"] == null || content_length === 0) return null;
|
|
22
|
+
if (req.destroyed) {
|
|
23
|
+
const readable = new ReadableStream();
|
|
24
|
+
readable.cancel();
|
|
25
|
+
return readable;
|
|
26
|
+
}
|
|
27
|
+
let size = 0;
|
|
28
|
+
let cancelled = false;
|
|
29
|
+
return new ReadableStream({
|
|
30
|
+
start(controller) {
|
|
31
|
+
if (body_size_limit !== void 0 && has_content_length && content_length > body_size_limit) {
|
|
32
|
+
const error = new SvelteKitError(413, "Payload Too Large", `Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`);
|
|
33
|
+
controller.error(error);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
/** @param {Error} error */
|
|
37
|
+
const on_error = (error) => {
|
|
38
|
+
cancelled = true;
|
|
39
|
+
controller.error(error);
|
|
40
|
+
};
|
|
41
|
+
const on_end = () => {
|
|
42
|
+
if (cancelled) return;
|
|
43
|
+
controller.close();
|
|
44
|
+
};
|
|
45
|
+
/** @param {Buffer} chunk */
|
|
46
|
+
const on_data = (chunk) => {
|
|
47
|
+
if (cancelled) return;
|
|
48
|
+
size += chunk.length;
|
|
49
|
+
if (body_size_limit !== void 0 && size > body_size_limit) {
|
|
50
|
+
cancelled = true;
|
|
51
|
+
const message = `request body size exceeded BODY_SIZE_LIMIT of ${body_size_limit}`;
|
|
52
|
+
const error = new SvelteKitError(413, "Payload Too Large", message);
|
|
53
|
+
controller.error(error);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (has_content_length && size > content_length) {
|
|
57
|
+
cancelled = true;
|
|
58
|
+
const message = `request body size exceeded content-length of ${content_length}`;
|
|
59
|
+
const error = new SvelteKitError(413, "Payload Too Large", message);
|
|
60
|
+
controller.error(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
controller.enqueue(chunk);
|
|
64
|
+
if (controller.desiredSize === null || controller.desiredSize <= 0) req.pause();
|
|
65
|
+
};
|
|
66
|
+
req.on("error", on_error);
|
|
67
|
+
req.on("end", on_end);
|
|
68
|
+
req.on("data", on_data);
|
|
69
|
+
body_data_listeners.set(req, on_data);
|
|
70
|
+
},
|
|
71
|
+
pull() {
|
|
72
|
+
req.resume();
|
|
73
|
+
},
|
|
74
|
+
cancel(reason) {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
req.destroy(reason);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @param {{
|
|
82
|
+
* request: import('http').IncomingMessage;
|
|
83
|
+
* response?: import('http').ServerResponse;
|
|
84
|
+
* base: string;
|
|
85
|
+
* bodySizeLimit?: number;
|
|
86
|
+
* }} options
|
|
87
|
+
* @returns {Request}
|
|
88
|
+
*/
|
|
89
|
+
function getRequest({ request, response, base, bodySizeLimit }) {
|
|
90
|
+
let headers = request.headers;
|
|
91
|
+
if (request.httpVersionMajor >= 2) {
|
|
92
|
+
headers = Object.assign({}, headers);
|
|
93
|
+
if (headers[":authority"]) headers.host = headers[":authority"];
|
|
94
|
+
delete headers[":authority"];
|
|
95
|
+
delete headers[":method"];
|
|
96
|
+
delete headers[":path"];
|
|
97
|
+
delete headers[":scheme"];
|
|
98
|
+
}
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
request.once("close", () => {
|
|
101
|
+
if (request.readableAborted) controller.abort();
|
|
102
|
+
});
|
|
103
|
+
response?.once("close", () => {
|
|
104
|
+
if (!response.writableEnded) controller.abort();
|
|
105
|
+
});
|
|
106
|
+
return new Request(base + request.url, {
|
|
107
|
+
duplex: "half",
|
|
108
|
+
method: request.method,
|
|
109
|
+
headers: Object.entries(headers),
|
|
110
|
+
signal: controller.signal,
|
|
111
|
+
body: request.method === "GET" || request.method === "HEAD" ? void 0 : get_raw_body(request, bodySizeLimit)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Drains any unconsumed request body once the response has been sent. When a
|
|
116
|
+
* route doesn't read the request body (for example a page route receiving a
|
|
117
|
+
* POST), the unread bytes remain buffered in the socket. On keep-alive
|
|
118
|
+
* connections Node's HTTP parser then reads those leftover bytes as the next
|
|
119
|
+
* request, fails to parse them, and resets the connection — losing any
|
|
120
|
+
* pipelined request. Resuming the request discards the bytes so the connection
|
|
121
|
+
* stays usable.
|
|
122
|
+
*
|
|
123
|
+
* Because `get_raw_body` attaches a `data` listener, Node marks the request as
|
|
124
|
+
* being consumed (`req._consuming`) and skips its own automatic drain, so we
|
|
125
|
+
* have to do it ourselves. The whole remaining body is read and discarded; this
|
|
126
|
+
* is the intended trade-off (keeping the connection reusable) over destroying it.
|
|
127
|
+
* @see https://github.com/sveltejs/kit/issues/14916
|
|
128
|
+
* @see https://github.com/sveltejs/kit/issues/15526
|
|
129
|
+
* @param {import('http').ServerResponse} res
|
|
130
|
+
*/
|
|
131
|
+
function drain_request(res) {
|
|
132
|
+
const req = res.req;
|
|
133
|
+
if (!req || req.readableEnded || req.destroyed) return;
|
|
134
|
+
const on_data = body_data_listeners.get(req);
|
|
135
|
+
if (on_data) {
|
|
136
|
+
req.removeListener("data", on_data);
|
|
137
|
+
body_data_listeners.delete(req);
|
|
138
|
+
}
|
|
139
|
+
req.resume();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @param {import('http').ServerResponse} res
|
|
143
|
+
* @param {Response} response
|
|
144
|
+
* @returns {void}
|
|
145
|
+
*/
|
|
146
|
+
function setResponse(res, response) {
|
|
147
|
+
res.once("finish", () => drain_request(res));
|
|
148
|
+
res.once("close", () => drain_request(res));
|
|
149
|
+
for (const [key, value] of response.headers) try {
|
|
150
|
+
res.setHeader(key, key === "set-cookie" ? response.headers.getSetCookie() : value);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
153
|
+
res.writeHead(500).end(String(error));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!response.body) {
|
|
157
|
+
res.writeHead(response.status);
|
|
158
|
+
res.end();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (response.body.locked) {
|
|
162
|
+
res.writeHead(response.status);
|
|
163
|
+
res.end("Fatal error: Response body is locked. This can happen when the response was already read (for example through 'response.json()' or 'response.text()').");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const reader = response.body.getReader();
|
|
167
|
+
if (res.destroyed) {
|
|
168
|
+
reader.cancel();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const cancel = (error) => {
|
|
172
|
+
res.off("close", cancel);
|
|
173
|
+
res.off("error", cancel);
|
|
174
|
+
reader.cancel(error).catch(noop);
|
|
175
|
+
if (error) res.destroy(error);
|
|
176
|
+
};
|
|
177
|
+
res.on("close", cancel);
|
|
178
|
+
res.on("error", cancel);
|
|
179
|
+
/** @type {Uint8Array<ArrayBuffer>[]} */
|
|
180
|
+
const buffered = [];
|
|
181
|
+
/** @type {ReturnType<typeof reader.read> | null} */
|
|
182
|
+
let pending = null;
|
|
183
|
+
probe();
|
|
184
|
+
async function probe() {
|
|
185
|
+
try {
|
|
186
|
+
/** @type {Promise<undefined>} */
|
|
187
|
+
const deadline = new Promise((fulfil) => setImmediate(() => fulfil(void 0)));
|
|
188
|
+
while (buffered.length < 2) {
|
|
189
|
+
pending = reader.read();
|
|
190
|
+
const result = await Promise.race([pending, deadline]);
|
|
191
|
+
if (!result) break;
|
|
192
|
+
pending = null;
|
|
193
|
+
if (result.done) {
|
|
194
|
+
if (!res.hasHeader("content-length") && !res.hasHeader("transfer-encoding")) res.setHeader("content-length", buffered.reduce((total, chunk) => total + chunk.byteLength, 0));
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
buffered.push(result.value);
|
|
198
|
+
}
|
|
199
|
+
if (res.destroyed) return;
|
|
200
|
+
res.writeHead(response.status);
|
|
201
|
+
await next();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (!res.headersSent) res.writeHead(response.status);
|
|
204
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function next() {
|
|
208
|
+
try {
|
|
209
|
+
for (;;) {
|
|
210
|
+
/** @type {Awaited<ReturnType<typeof reader.read>>} */
|
|
211
|
+
let result;
|
|
212
|
+
if (buffered.length > 0) result = {
|
|
213
|
+
done: false,
|
|
214
|
+
value: buffered.shift()
|
|
215
|
+
};
|
|
216
|
+
else if (pending) {
|
|
217
|
+
result = await pending;
|
|
218
|
+
pending = null;
|
|
219
|
+
} else result = await reader.read();
|
|
220
|
+
const { done, value } = result;
|
|
221
|
+
if (done) break;
|
|
222
|
+
if (!res.write(value)) {
|
|
223
|
+
res.once("drain", next);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
res.end();
|
|
228
|
+
} catch (error) {
|
|
229
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Converts a file on disk to a readable stream
|
|
235
|
+
* @param {string} file
|
|
236
|
+
* @returns {ReadableStream}
|
|
237
|
+
* @since 2.4.0
|
|
238
|
+
*/
|
|
239
|
+
function createReadableStream(file) {
|
|
240
|
+
return Readable.toWeb(createReadStream(file));
|
|
241
|
+
}
|
|
242
|
+
// ../../node_modules/.pnpm/@sveltejs+adapter-node@6.0.2_@sveltejs+kit@3.2.0_@sveltejs+vite-plugin-svelte@7.3.1_sve_f768d943589f92fcf48d61074f12cc67/node_modules/@sveltejs/adapter-node/src/utils.js
|
|
243
|
+
/**
|
|
244
|
+
* Parses the given value into number of bytes.
|
|
245
|
+
*
|
|
246
|
+
* @param {string} value - Size in bytes. Can also be specified with a unit suffix kilobytes (K), megabytes (M), or gigabytes (G).
|
|
247
|
+
* @returns {number}
|
|
248
|
+
*/
|
|
249
|
+
function parse_as_bytes(value) {
|
|
250
|
+
const multiplier = {
|
|
251
|
+
K: 1024,
|
|
252
|
+
M: 1048576,
|
|
253
|
+
G: 1073741824
|
|
254
|
+
}[value[value.length - 1]?.toUpperCase()] ?? 1;
|
|
255
|
+
return Number(multiplier != 1 ? value.substring(0, value.length - 1) : value) * multiplier;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Parses and validates an origin URL.
|
|
259
|
+
*
|
|
260
|
+
* @param {string | undefined} value - Origin URL with http:// or https:// protocol
|
|
261
|
+
* @returns {string | undefined} The validated origin, or undefined if value is undefined
|
|
262
|
+
* @throws {Error} If value is provided but invalid
|
|
263
|
+
*/
|
|
264
|
+
function parse_origin(value) {
|
|
265
|
+
if (value === void 0) return;
|
|
266
|
+
const trimmed = value.trim();
|
|
267
|
+
let url;
|
|
268
|
+
try {
|
|
269
|
+
url = new URL(trimmed);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
throw new Error(`Invalid ORIGIN: '${trimmed}'. ORIGIN must be a valid URL with http:// or https:// protocol. For example: 'http://localhost:3000' or 'https://my.site'`, { cause: error });
|
|
272
|
+
}
|
|
273
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error(`Invalid ORIGIN: '${trimmed}'. Only http:// and https:// protocols are supported. Received protocol: ${url.protocol}`);
|
|
274
|
+
return url.origin;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Formats the address the server is listening on.
|
|
278
|
+
*
|
|
279
|
+
* @param {string | false} path
|
|
280
|
+
* @param {string} host
|
|
281
|
+
* @param {string | false} port
|
|
282
|
+
* @param {import('node:net').AddressInfo | string | null} address
|
|
283
|
+
* @returns {string}
|
|
284
|
+
*/
|
|
285
|
+
function format_listening_address(path, host, port, address) {
|
|
286
|
+
if (path) return path;
|
|
287
|
+
if (address && typeof address === "object") return format({
|
|
288
|
+
protocol: "http:",
|
|
289
|
+
hostname: address.address,
|
|
290
|
+
port: address.port
|
|
291
|
+
});
|
|
292
|
+
return format({
|
|
293
|
+
protocol: "http:",
|
|
294
|
+
hostname: host,
|
|
295
|
+
port: String(port)
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// ../../node_modules/.pnpm/@sveltejs+adapter-node@6.0.2_@sveltejs+kit@3.2.0_@sveltejs+vite-plugin-svelte@7.3.1_sve_f768d943589f92fcf48d61074f12cc67/node_modules/@sveltejs/adapter-node/src/static.js
|
|
299
|
+
/** @import { IncomingMessage, ServerResponse } from 'node:http' */
|
|
300
|
+
/**
|
|
301
|
+
* @typedef {(req: IncomingMessage, res: ServerResponse, next: () => void | Promise<void>) => void | Promise<void>} Middleware
|
|
302
|
+
* @typedef {AssetEntry & { type?: string, cache_control?: string }} Asset
|
|
303
|
+
* @typedef {Asset | { location: string }} Entry
|
|
304
|
+
*/
|
|
305
|
+
/**
|
|
306
|
+
* Splits `req.url` into a decoded pathname and the search string.
|
|
307
|
+
* Decoding follows kit's router: reserved characters such as `%2F` stay
|
|
308
|
+
* encoded. An undecodable pathname is returned as-is, so it misses the
|
|
309
|
+
* asset table and falls through to SvelteKit's 400
|
|
310
|
+
* @param {import('node:http').IncomingMessage} req
|
|
311
|
+
*/
|
|
312
|
+
function split_url(req) {
|
|
313
|
+
let pathname = req.url;
|
|
314
|
+
let search = "";
|
|
315
|
+
const query_index = pathname.indexOf("?");
|
|
316
|
+
if (query_index !== -1) {
|
|
317
|
+
search = pathname.slice(query_index);
|
|
318
|
+
pathname = pathname.slice(0, query_index);
|
|
319
|
+
}
|
|
320
|
+
if (pathname.includes("%")) try {
|
|
321
|
+
pathname = pathname.split("%25").map(decodeURI).join("%25");
|
|
322
|
+
} catch {}
|
|
323
|
+
return {
|
|
324
|
+
pathname,
|
|
325
|
+
search
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Relative reference from `from` to `to`, which must differ only by a trailing slash.
|
|
330
|
+
* Keep in sync with the copy in `packages/kit/src/utils/url.js`
|
|
331
|
+
* @param {string} from
|
|
332
|
+
* @param {string} to
|
|
333
|
+
* @returns {string}
|
|
334
|
+
*/
|
|
335
|
+
function relative_pathname(from, to) {
|
|
336
|
+
const segment = to.replace(/\/$/, "").split("/").at(-1);
|
|
337
|
+
return from.endsWith("/") ? `../${segment}` : `./${segment}/`;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Parses `Accept-Encoding` and picks the preferred variant that exists
|
|
341
|
+
* @param {string | undefined} header
|
|
342
|
+
* @param {Asset} asset
|
|
343
|
+
* @returns {'br' | 'gz' | undefined}
|
|
344
|
+
*/
|
|
345
|
+
function negotiate(header, asset) {
|
|
346
|
+
if (!header || !(asset.br || asset.gz)) return;
|
|
347
|
+
/** @type {Map<string, number>} */
|
|
348
|
+
const weights = /* @__PURE__ */ new Map();
|
|
349
|
+
for (const part of header.toLowerCase().split(",")) {
|
|
350
|
+
const [coding, ...params] = part.split(";");
|
|
351
|
+
let weight = 1;
|
|
352
|
+
for (const param of params) {
|
|
353
|
+
const [name, value] = param.split("=");
|
|
354
|
+
if (name.trim() === "q") weight = parseFloat(value) || 0;
|
|
355
|
+
}
|
|
356
|
+
weights.set(coding.trim(), weight);
|
|
357
|
+
}
|
|
358
|
+
/** @param {string} coding */
|
|
359
|
+
const weight = (coding) => weights.get(coding) ?? weights.get("*") ?? 0;
|
|
360
|
+
const br = asset.br ? weight("br") : 0;
|
|
361
|
+
if ((asset.gz ? weight("gzip") : 0) > br) return "gz";
|
|
362
|
+
if (br > 0) return "br";
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Whether an `If-None-Match` value matches `etag`, using weak comparison
|
|
366
|
+
* @param {string | undefined} header
|
|
367
|
+
* @param {string} etag
|
|
368
|
+
*/
|
|
369
|
+
function etag_matches(header, etag) {
|
|
370
|
+
if (!header) return false;
|
|
371
|
+
if (header.trim() === "*") return true;
|
|
372
|
+
return header.split(",").some((tag) => tag.trim().replace(/^W\//, "") === etag);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Absolute file paths and content types for one table
|
|
376
|
+
* @param {string} dir
|
|
377
|
+
* @param {AssetTable} table
|
|
378
|
+
* @param {Record<string, string>} mime_types
|
|
379
|
+
* @returns {Map<string, Asset>}
|
|
380
|
+
*/
|
|
381
|
+
function resolve(dir, table, mime_types) {
|
|
382
|
+
/** @type {Map<string, Asset>} */
|
|
383
|
+
const files = /* @__PURE__ */ new Map();
|
|
384
|
+
for (const [key, entry] of table.entries) {
|
|
385
|
+
let type = mime_types[entry.file.slice(entry.file.lastIndexOf("."))];
|
|
386
|
+
if (type === "text/html") type += ";charset=utf-8";
|
|
387
|
+
files.set(key, {
|
|
388
|
+
...entry,
|
|
389
|
+
file: path.join(dir, entry.file),
|
|
390
|
+
type
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
for (const [alias, key] of table.aliases) files.set(alias, files.get(key));
|
|
394
|
+
return files;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* One lookup for every request, decided at boot: client assets (immutable below
|
|
398
|
+
* `app_path`), prerendered pages, and a 308 from the non-canonical trailing-slash
|
|
399
|
+
* form of a prerendered path to the canonical one. Client assets win a collision
|
|
400
|
+
* @param {{
|
|
401
|
+
* dir: string,
|
|
402
|
+
* base: string,
|
|
403
|
+
* app_path: string,
|
|
404
|
+
* mime_types: Record<string, string>,
|
|
405
|
+
* assets: AssetTable,
|
|
406
|
+
* prerendered_assets: AssetTable
|
|
407
|
+
* }} opts
|
|
408
|
+
* @returns {Map<string, Entry>}
|
|
409
|
+
*/
|
|
410
|
+
function create_file_map({ dir, base, app_path, mime_types, assets, prerendered_assets }) {
|
|
411
|
+
/** @type {Map<string, Entry>} */
|
|
412
|
+
const files = resolve(`${dir}/client${base}`, assets, mime_types);
|
|
413
|
+
const immutable = `/${app_path}/immutable/`;
|
|
414
|
+
for (const [key, asset] of files) if (key.startsWith(immutable))
|
|
415
|
+
/** @type {Asset} */ asset.cache_control = "public,max-age=31536000,immutable";
|
|
416
|
+
const prerendered = resolve(`${dir}/prerendered${base}`, prerendered_assets, mime_types);
|
|
417
|
+
for (const [key, asset] of prerendered) if (!files.has(key)) files.set(key, asset);
|
|
418
|
+
for (const key of prerendered.keys()) {
|
|
419
|
+
const inverted = key.at(-1) === "/" ? key.slice(0, -1) : key + "/";
|
|
420
|
+
if (inverted && !files.has(inverted)) files.set(inverted, { location: relative_pathname(inverted, key) });
|
|
421
|
+
}
|
|
422
|
+
return files;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Serves the closed set of files recorded at adapt time. Everything about a
|
|
426
|
+
* response is decided before the first request, so a request is one map
|
|
427
|
+
* lookup, header negotiation and a stream
|
|
428
|
+
* @param {Map<string, Entry>} files
|
|
429
|
+
* @returns {Middleware}
|
|
430
|
+
*/
|
|
431
|
+
function serve_static(files) {
|
|
432
|
+
return (req, res, next) => {
|
|
433
|
+
const { pathname, search } = split_url(req);
|
|
434
|
+
const asset = files.get(pathname);
|
|
435
|
+
if (!asset) return next();
|
|
436
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
437
|
+
res.writeHead(405, { allow: "GET, HEAD" }).end();
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if ("location" in asset) {
|
|
441
|
+
res.writeHead(308, { location: asset.location + search }).end();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
let file = asset.file;
|
|
445
|
+
let size = asset.size;
|
|
446
|
+
let etag = `"${asset.etag}"`;
|
|
447
|
+
const variant = negotiate(req.headers["accept-encoding"], asset);
|
|
448
|
+
if (variant) {
|
|
449
|
+
size = asset[variant];
|
|
450
|
+
file += `.${variant}`;
|
|
451
|
+
etag = `"${asset.etag}.${variant}"`;
|
|
452
|
+
}
|
|
453
|
+
/** @type {Record<string, string | number>} */
|
|
454
|
+
const headers = { etag };
|
|
455
|
+
if (asset.br || asset.gz) headers.vary = "Accept-Encoding";
|
|
456
|
+
if (asset.cache_control) headers["cache-control"] = asset.cache_control;
|
|
457
|
+
if (etag_matches(req.headers["if-none-match"], etag)) {
|
|
458
|
+
res.writeHead(304, headers).end();
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
headers["content-length"] = size;
|
|
462
|
+
headers["accept-ranges"] = "bytes";
|
|
463
|
+
if (asset.type) headers["content-type"] = asset.type;
|
|
464
|
+
if (variant) headers["content-encoding"] = variant === "gz" ? "gzip" : "br";
|
|
465
|
+
/** @type {{ start?: number, end?: number }} */
|
|
466
|
+
const range = {};
|
|
467
|
+
let status = 200;
|
|
468
|
+
const if_range = req.headers["if-range"];
|
|
469
|
+
if (req.method === "GET" && req.headers.range && (!if_range || if_range === etag)) {
|
|
470
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range);
|
|
471
|
+
if (match && (match[1] || match[2])) {
|
|
472
|
+
let start = match[1] ? parseInt(match[1], 10) : NaN;
|
|
473
|
+
let end = match[2] ? parseInt(match[2], 10) : size - 1;
|
|
474
|
+
if (isNaN(start)) {
|
|
475
|
+
start = Math.max(size - end, 0);
|
|
476
|
+
end = size - 1;
|
|
477
|
+
} else end = Math.min(end, size - 1);
|
|
478
|
+
if (start >= size || start > end) {
|
|
479
|
+
res.writeHead(416, { "content-range": `bytes */${size}` }).end();
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
status = 206;
|
|
483
|
+
headers["content-range"] = `bytes ${start}-${end}/${size}`;
|
|
484
|
+
headers["content-length"] = end - start + 1;
|
|
485
|
+
range.start = start;
|
|
486
|
+
range.end = end;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
res.writeHead(status, headers);
|
|
490
|
+
if (req.method === "HEAD") {
|
|
491
|
+
res.end();
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
pipeline(fs.createReadStream(file, range), res, () => {});
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
// ../../node_modules/.pnpm/@sveltejs+adapter-node@6.0.2_@sveltejs+kit@3.2.0_@sveltejs+vite-plugin-svelte@7.3.1_sve_f768d943589f92fcf48d61074f12cc67/node_modules/@sveltejs/adapter-node/src/handler.js
|
|
498
|
+
/** @import { IncomingHttpHeaders } from 'node:http' */
|
|
499
|
+
/** @import { Middleware } from './static.js' */
|
|
500
|
+
var env_origin = env("ORIGIN", void 0);
|
|
501
|
+
if (origin && env_origin !== void 0) console.warn(`${env_prefix}ORIGIN is ignored because the SvelteKit configuration \`paths.origin\` setting was set to ${origin}`);
|
|
502
|
+
var public_origin = origin || parse_origin(env_origin);
|
|
503
|
+
var xff_depth = parseInt(env("XFF_DEPTH", "1"));
|
|
504
|
+
var address_header = env("ADDRESS_HEADER", "").toLowerCase();
|
|
505
|
+
var protocol_header = env("PROTOCOL_HEADER", "").toLowerCase();
|
|
506
|
+
var host_header = env("HOST_HEADER", "").toLowerCase();
|
|
507
|
+
var port_header = env("PORT_HEADER", "").toLowerCase();
|
|
508
|
+
var body_size_limit = parse_as_bytes(env("BODY_SIZE_LIMIT", "512K"));
|
|
509
|
+
if (isNaN(body_size_limit)) throw new Error(`Invalid BODY_SIZE_LIMIT: '${env("BODY_SIZE_LIMIT")}'. Please provide a numeric value.`);
|
|
510
|
+
var asset_dir = `${dir}/client${base}`;
|
|
511
|
+
await server.init({
|
|
512
|
+
env: process.env,
|
|
513
|
+
read: (file) => createReadableStream(`${asset_dir}/${file}`)
|
|
514
|
+
});
|
|
515
|
+
/** @type {Middleware} */
|
|
516
|
+
var ssr = async (req, res, next) => {
|
|
517
|
+
try {
|
|
518
|
+
await render(req, res, next);
|
|
519
|
+
} catch (error) {
|
|
520
|
+
console.error(error);
|
|
521
|
+
if (res.headersSent) {
|
|
522
|
+
res.destroy();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
526
|
+
res.writeHead(500).end("Internal Server Error");
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
/** @type {Middleware} */
|
|
530
|
+
var render = async (req, res) => {
|
|
531
|
+
/** @type {Request} */
|
|
532
|
+
let request;
|
|
533
|
+
let request_origin = public_origin;
|
|
534
|
+
if (!request_origin) try {
|
|
535
|
+
request_origin = get_origin(req.headers);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
console.error(`Could not determine request origin: ${error instanceof Error ? error.message : String(error)}`);
|
|
538
|
+
res.statusCode = 400;
|
|
539
|
+
res.end("Bad Request");
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
try {
|
|
543
|
+
request = getRequest({
|
|
544
|
+
base: request_origin,
|
|
545
|
+
request: req,
|
|
546
|
+
response: res,
|
|
547
|
+
bodySizeLimit: body_size_limit
|
|
548
|
+
});
|
|
549
|
+
} catch {
|
|
550
|
+
res.statusCode = 400;
|
|
551
|
+
res.end("Bad Request");
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const response = await server.respond(request, {
|
|
555
|
+
platform: { req },
|
|
556
|
+
getClientAddress: () => {
|
|
557
|
+
if (address_header) {
|
|
558
|
+
if (!(address_header in req.headers)) throw new Error(`Address header was specified with ${env_prefix + "ADDRESS_HEADER"}=${address_header} but is absent from request`);
|
|
559
|
+
const value = req.headers[address_header] || "";
|
|
560
|
+
if (address_header === "x-forwarded-for") {
|
|
561
|
+
const addresses = value.split(",");
|
|
562
|
+
if (xff_depth < 1) throw new Error(`${env_prefix + "XFF_DEPTH"} must be a positive integer`);
|
|
563
|
+
if (xff_depth > addresses.length) throw new Error(`${env_prefix + "XFF_DEPTH"} is ${xff_depth}, but only found ${addresses.length} addresses`);
|
|
564
|
+
return addresses[addresses.length - xff_depth].trim();
|
|
565
|
+
}
|
|
566
|
+
return value;
|
|
567
|
+
}
|
|
568
|
+
return req.connection?.remoteAddress || req.connection?.socket?.remoteAddress || req.socket?.remoteAddress || req.info?.remoteAddress;
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
if (response.headers.get("content-type") === "text/event-stream") res.setHeader("x-accel-buffering", "no");
|
|
572
|
+
setResponse(res, response);
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* @param {string} name
|
|
576
|
+
* @param {string | string[] | undefined} value
|
|
577
|
+
* @returns {string | undefined}
|
|
578
|
+
*/
|
|
579
|
+
function normalise_header(name, value) {
|
|
580
|
+
if (!name) return void 0;
|
|
581
|
+
if (Array.isArray(value)) {
|
|
582
|
+
if (value.length === 0) return void 0;
|
|
583
|
+
if (value.length === 1) return value[0];
|
|
584
|
+
throw new Error(`Multiple values provided for ${name} header where only one expected: ${value}`);
|
|
585
|
+
}
|
|
586
|
+
return value;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* @param {IncomingHttpHeaders} headers
|
|
590
|
+
* @returns {string}
|
|
591
|
+
*/
|
|
592
|
+
function get_origin(headers) {
|
|
593
|
+
const protocol = decodeURIComponent(normalise_header(protocol_header, headers[protocol_header]) || "https");
|
|
594
|
+
if (protocol.includes(":")) throw new Error(`The ${protocol_header} header specified ${protocol} which is an invalid because it includes \`:\`. It should only contain the protocol scheme (e.g. \`https\`)`);
|
|
595
|
+
const host = normalise_header(host_header, headers[host_header]) || normalise_header("host", headers["host"]);
|
|
596
|
+
if (!host) {
|
|
597
|
+
const header_names = host_header ? `${host_header} or host headers` : "host header";
|
|
598
|
+
throw new Error(`Could not determine host. The request must have a value provided by the ${header_names}`);
|
|
599
|
+
}
|
|
600
|
+
const port = normalise_header(port_header, headers[port_header]);
|
|
601
|
+
if (port && isNaN(+port)) throw new Error(`The ${port_header} header specified ${port} which is an invalid port because it is not a number. The value should only contain the port number (e.g. 443)`);
|
|
602
|
+
return port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;
|
|
603
|
+
}
|
|
604
|
+
var serve = serve_static(create_file_map({
|
|
605
|
+
dir,
|
|
606
|
+
base,
|
|
607
|
+
app_path,
|
|
608
|
+
mime_types,
|
|
609
|
+
assets,
|
|
610
|
+
prerendered_assets
|
|
611
|
+
}));
|
|
612
|
+
/** @type {Middleware} */
|
|
613
|
+
var handler = (req, res, next) => serve(req, res, () => ssr(req, res, next));
|
|
614
|
+
export { format_listening_address as n, handler as t };
|
|
615
|
+
|
|
616
|
+
//# sourceMappingURL=adapter-node-handler.js.map
|