vue-ssr-lite 0.1.13 → 0.2.2

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.
Files changed (42) hide show
  1. package/README.md +169 -159
  2. package/dist/SsrApplicationRuntime.d.ts.map +1 -1
  3. package/dist/SsrBrowserRuntime.d.ts +7 -6
  4. package/dist/SsrBrowserRuntime.d.ts.map +1 -1
  5. package/dist/SsrConfigCompileRuntime.d.ts +40 -0
  6. package/dist/SsrConfigCompileRuntime.d.ts.map +1 -0
  7. package/dist/SsrConfigRuntime.d.ts +4 -0
  8. package/dist/SsrConfigRuntime.d.ts.map +1 -0
  9. package/dist/SsrConfigTypes.d.ts +106 -0
  10. package/dist/SsrConfigTypes.d.ts.map +1 -0
  11. package/dist/SsrDomainRuntime.d.ts +38 -0
  12. package/dist/SsrDomainRuntime.d.ts.map +1 -0
  13. package/dist/SsrReactivityRuntime.d.ts +8 -1
  14. package/dist/SsrReactivityRuntime.d.ts.map +1 -1
  15. package/dist/SsrRenderRuntime.d.ts.map +1 -1
  16. package/dist/SsrRequestResolution.d.ts +3 -1
  17. package/dist/SsrRequestResolution.d.ts.map +1 -1
  18. package/dist/SsrRuntimeTypes.d.ts +6 -21
  19. package/dist/SsrRuntimeTypes.d.ts.map +1 -1
  20. package/dist/SsrTestFixtures.d.ts +8 -0
  21. package/dist/SsrTestFixtures.d.ts.map +1 -0
  22. package/dist/chunks/SsrApplicationRuntime-D4arUtsy.mjs +238 -0
  23. package/dist/chunks/SsrConfigRuntime-D0DkOrVQ.mjs +4 -0
  24. package/dist/chunks/SsrReactivityRuntime-CroM1WJG.mjs +28 -0
  25. package/dist/chunks/SsrServerRuntime-D7cDSFNm.mjs +1004 -0
  26. package/dist/cli.mjs +34 -34
  27. package/dist/client.d.ts +1 -0
  28. package/dist/client.d.ts.map +1 -1
  29. package/dist/client.mjs +79 -56
  30. package/dist/index.d.ts +4 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.mjs +25 -19
  33. package/dist/server/SsrHostRuntime.d.ts +52 -2
  34. package/dist/server/SsrHostRuntime.d.ts.map +1 -1
  35. package/dist/server/SsrServerRuntime.d.ts.map +1 -1
  36. package/dist/server.d.ts +3 -0
  37. package/dist/server.d.ts.map +1 -1
  38. package/dist/server.mjs +73 -60
  39. package/package.json +1 -1
  40. package/dist/chunks/SsrApplicationRuntime-lMR_sMdk.mjs +0 -155
  41. package/dist/chunks/SsrReactivityRuntime-CUbPx7ew.mjs +0 -9
  42. package/dist/chunks/SsrServerRuntime-nBan8KxD.mjs +0 -731
@@ -1,731 +0,0 @@
1
- import { createServer as ie } from "node:http";
2
- import { stat as J, readFile as re } from "node:fs/promises";
3
- import { resolve as N, sep as X, extname as oe } from "node:path";
4
- import { renderToString as ce } from "@vue/server-renderer";
5
- import { c as le, e as de } from "./SsrApplicationRuntime-lMR_sMdk.mjs";
6
- import { c as ue } from "./SsrDiagnosticsRuntime-B5VbSgsA.mjs";
7
- import { a as he } from "./SsrSerialization-k-3aCFYt.mjs";
8
- import { r as B, p as me, i as fe } from "./SsrHtmlRuntime-cTFsMSAZ.mjs";
9
- const F = () => globalThis.performance?.now?.() ?? Date.now(), Z = (e) => new TextEncoder().encode(e).byteLength, Q = (e, r, o, s) => {
10
- for (const i of s) {
11
- const n = { requestId: r, applicationId: o, code: i.code };
12
- e?.warn ? e.warn(`ssr.diagnostic.${i.code}`, n) : console.warn(`[vue-ssr-lite] ${i.message}`, n);
13
- }
14
- }, pe = async (e, r, o = {}) => {
15
- const s = F(), i = Math.max(1, Math.floor(o.maxResolutionPasses ?? 4)), n = o.resolutionDeadlineMs ?? 0, u = o.diagnostics ?? process.env.NODE_ENV !== "production", v = de(!0);
16
- let C = s, p = s, m = s, S, t, a = "", f = "", c = 0, x;
17
- const H = async () => {
18
- if (!t) return;
19
- const w = t;
20
- t = void 0;
21
- try {
22
- await e.cleanup?.(w.context);
23
- } catch (l) {
24
- console.error("[vue-ssr-lite] application cleanup failed", l);
25
- }
26
- try {
27
- w.hydration.dispose();
28
- } catch (l) {
29
- console.error("[vue-ssr-lite] hydration cleanup failed", l);
30
- }
31
- };
32
- try {
33
- let w = !1;
34
- for (let y = 0; y < i && !w; y += 1) {
35
- if (c = y + 1, v.beginPass(y), t = await le(e, {
36
- server: !0,
37
- request: r,
38
- resumeState: y === 0 ? void 0 : S,
39
- resolution: v
40
- }), y === 0 && (C = F()), t.router) {
41
- const b = new URL(r.url);
42
- await t.router.push(`${b.pathname}${b.search}${b.hash}`), await t.router.isReady(), t.router.currentRoute.value.matched.length === 0 && (t.context.response.statusCode = 404);
43
- }
44
- y === 0 && (p = F());
45
- const A = {};
46
- a = await ce(t.app, A), f = A.teleports?.body ?? "", m = F();
47
- const g = v.pendingWork(), j = v.additionalPassRequested(), U = y === i - 1;
48
- if (g.length === 0 && !j || U) {
49
- w = !0, U && (g.length > 0 || j) && Q(o.logger, r.requestId, e.id, [
50
- {
51
- code: "resolution-pass-limit",
52
- message: `Resolution did not settle within ${i} render passes; serializing the last render.`
53
- }
54
- ]);
55
- break;
56
- }
57
- await v.drain(n, r.signal), S = t.hydration.collect(), await H();
58
- }
59
- if (!t) throw new Error("SSR render produced no application instance.");
60
- const l = await e.resolveHead?.(t.context) ?? t.context.head.value;
61
- u && Q(
62
- o.logger,
63
- r.requestId,
64
- e.id,
65
- ue({
66
- html: a,
67
- route: t.router?.currentRoute.value ?? null,
68
- requestUrl: r.url,
69
- applicationId: e.id
70
- })
71
- );
72
- const d = {
73
- version: 1,
74
- applicationId: e.id,
75
- publicConfig: r.publicConfig,
76
- application: t.context.state,
77
- plugins: t.hydration.collect()
78
- }, P = Z(he(d)), I = F();
79
- return {
80
- html: a,
81
- teleports: f,
82
- head: l,
83
- response: t.context.response,
84
- hydrationState: d,
85
- metrics: {
86
- requestId: r.requestId,
87
- applicationId: e.id,
88
- contextDurationMs: C - s,
89
- routeDurationMs: p - C,
90
- renderDurationMs: m - p,
91
- totalDurationMs: I - s,
92
- htmlBytes: Z(a),
93
- stateBytes: P,
94
- renderPasses: c
95
- }
96
- };
97
- } catch (w) {
98
- throw x = w, w;
99
- } finally {
100
- let w;
101
- if (t) {
102
- try {
103
- await e.cleanup?.(t.context);
104
- } catch (l) {
105
- w = l, console.error("[vue-ssr-lite] application cleanup failed", l);
106
- }
107
- try {
108
- t.hydration.dispose();
109
- } catch (l) {
110
- console.error("[vue-ssr-lite] hydration cleanup failed", l), w || (w = l);
111
- }
112
- }
113
- if (v.dispose(), !x && w) throw w;
114
- }
115
- }, we = {
116
- ".css": "text/css; charset=utf-8",
117
- ".gif": "image/gif",
118
- ".html": "text/html; charset=utf-8",
119
- ".ico": "image/x-icon",
120
- ".jpeg": "image/jpeg",
121
- ".jpg": "image/jpeg",
122
- ".js": "text/javascript; charset=utf-8",
123
- ".json": "application/json; charset=utf-8",
124
- ".map": "application/json; charset=utf-8",
125
- ".png": "image/png",
126
- ".svg": "image/svg+xml",
127
- ".txt": "text/plain; charset=utf-8",
128
- ".webp": "image/webp",
129
- ".woff": "font/woff",
130
- ".woff2": "font/woff2",
131
- ".xml": "application/xml; charset=utf-8"
132
- }, ge = async (e, r, o) => {
133
- try {
134
- const s = decodeURIComponent(r).replace(/^\/+/, "");
135
- if (!s || o.includes(s)) return null;
136
- const i = N(e, s), n = e.endsWith(X) ? e : `${e}${X}`;
137
- return !i.startsWith(n) || !(await J(i)).isFile() ? null : {
138
- statusCode: 200,
139
- body: await re(i),
140
- headers: {
141
- "content-type": we[oe(i)] || "application/octet-stream",
142
- "cache-control": r.startsWith("/assets/") ? "public, max-age=31536000, immutable" : "public, max-age=3600"
143
- }
144
- };
145
- } catch {
146
- return null;
147
- }
148
- }, G = (e) => String(Array.isArray(e) ? e[0] : e || "").split(",", 1)[0].trim(), O = (e) => {
149
- const r = G(e);
150
- if (!r || r.length > 512 || /[\u0000-\u0020\u007f]/.test(r) || /[\\/@?#]/.test(r))
151
- return "";
152
- try {
153
- const o = r.includes(":") && r.split(":").length > 2 && !r.startsWith("[") ? `[${r}]` : r, s = new URL(`http://${o}`);
154
- if (s.username || s.password || s.pathname !== "/" || s.search || s.hash)
155
- return "";
156
- const i = s.hostname.toLowerCase().replace(/\.$/, "");
157
- return i ? `${i.includes(":") && !i.startsWith("[") ? `[${i}]` : i}${s.port ? `:${s.port}` : ""}` : "";
158
- } catch {
159
- return "";
160
- }
161
- }, V = (e) => {
162
- const r = O(e);
163
- if (!r) return "";
164
- if (r.startsWith("[")) {
165
- const o = r.indexOf("]");
166
- return o > 0 ? r.slice(1, o) : "";
167
- }
168
- return r.replace(/:\d+$/, "");
169
- }, ye = (e) => {
170
- const r = e.trim().toLowerCase();
171
- if (r === "*") return "*";
172
- if (r.startsWith("*.")) {
173
- const o = V(r.slice(2));
174
- return o && !o.includes(":") && !o.includes("*") ? `*.${o}` : "";
175
- }
176
- return O(r);
177
- }, ve = (e, r) => {
178
- const o = V(e), s = ye(r);
179
- return !o || !s ? !1 : s === "*" ? !0 : s.startsWith("*.") ? o.endsWith(`.${s.slice(2)}`) : O(e) === s || o === V(s);
180
- }, Se = (e, r, o = !1) => O(o && G(e) || r), xe = (e, r, o = !1) => {
181
- if (!o) return r;
182
- const s = G(e).toLowerCase();
183
- return s === "http" || s === "https" ? s : r;
184
- }, be = (e, r, o) => {
185
- const s = e.find(
186
- (n) => n.hosts.some(
187
- (u) => u !== "*" && ve(r, u)
188
- )
189
- );
190
- if (s) return s;
191
- const i = e.find((n) => n.hosts.includes("*"));
192
- return i || (e.find((n) => n.id === o) ?? null);
193
- }, Y = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/, Ee = (e, r = [], o = []) => {
194
- const s = new Set(r.filter((u) => Y.test(u))), i = new Set(o.filter((u) => Y.test(u)));
195
- if (!e || s.size === 0) return;
196
- const n = String(e).split(";").map((u) => u.trim()).filter(Boolean).filter((u) => {
197
- const v = u.indexOf("=");
198
- if (v <= 0) return !1;
199
- const C = u.slice(0, v).trim();
200
- return s.has(C) && !i.has(C);
201
- });
202
- return n.length ? n.join("; ") : void 0;
203
- }, Re = (e) => typeof e == "string" ? new TextEncoder().encode(e).byteLength : e?.byteLength ?? 0, q = (e) => ({
204
- statusCode: e.statusCode,
205
- body: e.body instanceof Uint8Array ? e.body.slice() : e.body,
206
- headers: e.headers ? { ...e.headers } : void 0
207
- }), Oe = (e = {}) => {
208
- const r = Number(e.maxEntries ?? 500), o = Number(e.maxBytes ?? 32 * 1024 * 1024), s = Number.isFinite(r) ? Math.max(1, Math.floor(r)) : 500, i = Number.isFinite(o) ? Math.max(1, Math.floor(o)) : 32 * 1024 * 1024, n = /* @__PURE__ */ new Map();
209
- let u = 0;
210
- const v = (p) => {
211
- const m = n.get(p);
212
- return m ? (n.delete(p), u -= m.size, !0) : !1;
213
- }, C = () => {
214
- const p = Date.now();
215
- for (const [m, S] of n)
216
- S.expiresAt <= p && v(m);
217
- for (; n.size > s || u > i; ) {
218
- const m = n.keys().next().value;
219
- if (!m) break;
220
- v(m);
221
- }
222
- };
223
- return {
224
- get(p) {
225
- const m = n.get(p);
226
- return m ? m.expiresAt <= Date.now() ? (v(p), null) : (n.delete(p), n.set(p, m), q(m.response)) : null;
227
- },
228
- set(p, m, S) {
229
- const t = Number(S.ttlMs);
230
- if (!Number.isFinite(t) || t <= 0) return;
231
- v(p);
232
- const a = q(m), f = Re(a.body);
233
- f > i || (n.set(p, {
234
- response: a,
235
- expiresAt: Date.now() + t,
236
- size: f,
237
- tags: new Set(S.tags ?? [])
238
- }), u += f, C());
239
- },
240
- invalidate(p = {}) {
241
- const m = new Set(p.keys ?? []), S = new Set(p.tags ?? []);
242
- let t = 0;
243
- for (const [a, f] of n)
244
- (!m.size && !S.size || m.has(a) || [...S].some((x) => f.tags.has(x))) && v(a) && (t += 1);
245
- return t;
246
- }
247
- };
248
- }, Ce = async (e, r, o) => {
249
- if (!o || r.method !== "GET" || r.cookie || !Number.isFinite(o.ttlMs) || o.ttlMs <= 0)
250
- return null;
251
- const s = o.vary ? await o.vary(r) : "";
252
- return s == null ? null : JSON.stringify([
253
- "vue-ssr-lite:v1",
254
- e,
255
- r.host,
256
- r.pathname,
257
- r.search,
258
- s
259
- ]);
260
- }, Pe = (e, r, o) => {
261
- const s = Object.entries(e.headers ?? {}), i = String(
262
- s.find(([u]) => u.toLowerCase() === "cache-control")?.[1] || ""
263
- ).toLowerCase();
264
- return e.statusCode === 200 && typeof e.body == "string" && !s.some(([u]) => u.toLowerCase() === "set-cookie") && !i.includes("private") && !i.includes("no-store") && (o.shouldCache?.(e, r) ?? !0);
265
- };
266
- class se extends Error {
267
- constructor() {
268
- super("SSR request timed out."), this.name = "SsrRequestTimeoutError";
269
- }
270
- }
271
- const $e = (e) => {
272
- const r = e ?? 4173;
273
- if (!Number.isInteger(r) || r < 0 || r > 65535)
274
- throw new Error("SSR server port must be an integer between 0 and 65535.");
275
- return r;
276
- }, Me = (e) => e === "0.0.0.0" || e === "::" || e === "::1" ? "localhost" : e, Ie = (e, r, o) => {
277
- const s = `http://${Me(e)}:${r}/`;
278
- console.log(
279
- [
280
- "",
281
- "✓ Server Ready",
282
- "",
283
- ` ➜ Local: ${s}`,
284
- ` ➜ Role: ${o}`,
285
- ""
286
- ].join(`
287
- `)
288
- );
289
- }, ee = async (e) => {
290
- const o = e?.default ?? e, s = typeof o == "function" ? await o() : o;
291
- if (!s?.name || !Array.isArray(s.entries) || !s.server)
292
- throw new Error("The SSR runtime module does not export a valid runtime definition.");
293
- const i = /* @__PURE__ */ new Set();
294
- for (const n of s.entries) {
295
- if (!n.id || i.has(n.id))
296
- throw new Error("SSR runtime entry ids must be present and unique.");
297
- if (i.add(n.id), !n.template || !n.hosts?.length)
298
- throw new Error(`SSR runtime entry "${n.id}" requires a template and hosts.`);
299
- const u = !n.roles?.length || !s.server.role || n.roles.includes(s.server.role);
300
- if (n.kind === "ssr" && u && !n.application)
301
- throw new Error(`SSR entry "${n.id}" requires an application definition.`);
302
- }
303
- return s;
304
- }, D = {
305
- "referrer-policy": "strict-origin-when-cross-origin",
306
- "x-content-type-options": "nosniff",
307
- "x-frame-options": "SAMEORIGIN"
308
- }, k = (e, r) => {
309
- if (e.method !== "GET" && e.method !== "HEAD") return !1;
310
- if (e.headers["sec-fetch-mode"] === "navigate") return !0;
311
- const o = String(e.headers.accept || "");
312
- return o.includes("text/html") ? !0 : (!o || o === "*/*") && !oe(r);
313
- }, Ae = (e, r, o = "") => r.end(e.method === "HEAD" ? "" : o), R = (e, r, o) => {
314
- r.writeHead(o.statusCode, o.headers ?? {}), Ae(e, r, o.body ?? "");
315
- }, T = (e, r, o, s) => R(e, r, {
316
- statusCode: o,
317
- body: JSON.stringify(s),
318
- headers: {
319
- "content-type": "application/json; charset=utf-8",
320
- "cache-control": "no-store"
321
- }
322
- }), te = async (e, r, o) => {
323
- if (!Number.isFinite(r) || r <= 0) return e;
324
- let s;
325
- const i = new Promise((n, u) => {
326
- s = setTimeout(() => {
327
- o.abort(), u(new se());
328
- }, r);
329
- });
330
- try {
331
- return await Promise.race([e, i]);
332
- } finally {
333
- s && clearTimeout(s);
334
- }
335
- }, Te = (e) => e.headers, He = (e, r, o) => new Promise((s, i) => {
336
- e.middlewares(r, o, (n) => {
337
- n ? i(n) : s();
338
- });
339
- }), We = async (e) => {
340
- let r = !1;
341
- const o = await ee(await e.loadRuntime()), s = o.server, i = s.host || "0.0.0.0", n = $e(s.port), u = N(
342
- s.root || e.root,
343
- s.clientOutDir || "dist/client"
344
- ), v = async () => e.production ? o : ee(await e.loadRuntime()), C = async (t, a, f) => {
345
- const c = t.server.root || e.root, x = await re(
346
- N(e.production ? u : c, a),
347
- "utf8"
348
- );
349
- if (e.production || !e.vite) return x;
350
- const H = `/${a.replaceAll("\\", "/").replace(/^\/+/, "")}`;
351
- return e.vite.transformIndexHtml(H, x, f);
352
- }, p = async (t) => {
353
- const a = t.server.root || e.root, f = t.entries.filter(
354
- (c) => !c.roles?.length || !t.server.role || c.roles.includes(t.server.role)
355
- );
356
- await Promise.all(
357
- f.map(async (c) => {
358
- if (!(await J(
359
- N(e.production ? u : a, c.template)
360
- )).isFile())
361
- throw new Error(`SSR client entry is missing: ${c.template}`);
362
- })
363
- ), await Promise.all((t.readiness ?? []).map((c) => c.run()));
364
- }, m = o.entries.filter(
365
- (t) => !t.roles?.length || !o.server.role || t.roles.includes(o.server.role)
366
- );
367
- await Promise.all(
368
- m.map(async (t) => {
369
- const a = o.server.root || e.root;
370
- if (!(await J(
371
- N(e.production ? u : a, t.template)
372
- )).isFile()) throw new Error(`Missing client entry: ${t.template}`);
373
- })
374
- );
375
- const S = ie(async (t, a) => {
376
- const f = Date.now();
377
- let c = "/", x = "unknown", H;
378
- const w = new AbortController();
379
- t.once("aborted", () => w.abort()), a.once("close", () => {
380
- a.writableEnded || w.abort();
381
- });
382
- try {
383
- const l = await v(), d = l.server, P = new URL(t.url || "/", "http://internal");
384
- c = P.pathname;
385
- const I = d.healthPath || "/healthz", y = d.readinessPath || "/readyz";
386
- if (c === I)
387
- return T(t, a, 200, {
388
- status: "ok",
389
- service: l.name,
390
- role: d.role || "default",
391
- timestamp: new Date(f).toISOString()
392
- });
393
- if (c === y) {
394
- if (r)
395
- return T(t, a, 503, {
396
- status: "error",
397
- service: l.name,
398
- message: "Server is shutting down."
399
- });
400
- try {
401
- return await p(l), T(t, a, 200, {
402
- status: "ok",
403
- service: l.name,
404
- role: d.role || "default"
405
- });
406
- } catch {
407
- return T(t, a, 503, {
408
- status: "error",
409
- service: l.name,
410
- message: "A required dependency is unavailable."
411
- });
412
- }
413
- }
414
- const A = Se(
415
- t.headers["x-forwarded-host"],
416
- t.headers.host,
417
- d.trustProxy
418
- );
419
- if (!A)
420
- return R(t, a, {
421
- statusCode: 400,
422
- body: k(t, c) ? B("Invalid request", "The Host header is invalid.") : JSON.stringify({ status: "error", message: "Invalid Host header." }),
423
- headers: {
424
- "content-type": k(t, c) ? "text/html; charset=utf-8" : "application/json; charset=utf-8",
425
- "cache-control": "no-store",
426
- ...D
427
- }
428
- });
429
- const g = be(
430
- l.entries,
431
- A,
432
- l.defaultEntryId
433
- );
434
- if (!g)
435
- return T(t, a, 421, {
436
- status: "error",
437
- service: l.name,
438
- message: "No application entry serves this host."
439
- });
440
- if (x = g.id, g.roles?.length && d.role && !g.roles.includes(d.role)) {
441
- const h = `Runtime role does not serve entry "${g.id}".`;
442
- return R(t, a, {
443
- statusCode: 421,
444
- body: k(t, c) ? B("Misdirected request", h) : JSON.stringify({ status: "error", message: h }),
445
- headers: {
446
- "content-type": k(t, c) ? "text/html; charset=utf-8" : "application/json; charset=utf-8",
447
- "cache-control": "no-store",
448
- ...D
449
- }
450
- });
451
- }
452
- const j = xe(
453
- t.headers["x-forwarded-proto"],
454
- t.socket.encrypted ? "https" : "http",
455
- d.trustProxy
456
- ), U = Ee(
457
- t.headers.cookie,
458
- d.cookieAllowlist,
459
- d.cookieDenylist
460
- ), b = {
461
- requestId: String(t.headers["x-request-id"] || "").trim() || `${f.toString(36)}-${Math.random().toString(36).slice(2, 10)}`,
462
- url: new URL(
463
- `${P.pathname}${P.search}`,
464
- `${j}://${A}`
465
- ).href,
466
- host: A,
467
- protocol: j,
468
- method: t.method || "GET",
469
- headers: Te(t),
470
- cookie: U,
471
- publicConfig: d.publicConfig,
472
- signal: w.signal,
473
- pathname: c,
474
- search: P.search,
475
- entryId: g.id
476
- };
477
- H = b;
478
- const ne = {
479
- signal: w.signal,
480
- logger: d.logger
481
- };
482
- for (const h of l.endpoints ?? []) {
483
- if (!h.match(b)) continue;
484
- const $ = await te(
485
- Promise.resolve(h.handle(b, ne)),
486
- d.requestTimeoutMs ?? 15e3,
487
- w
488
- );
489
- if ($) return R(t, a, $);
490
- }
491
- if (e.production) {
492
- const h = await ge(
493
- u,
494
- c,
495
- l.entries.map(({ template: $ }) => $)
496
- );
497
- if (h) return R(t, a, h);
498
- } else if (e.vite && (c.startsWith("/src/") || c.startsWith("/@") || c.includes(".") || c === "/__vite_ping") && (await He(e.vite, t, a), a.writableEnded))
499
- return;
500
- if (!k(t, c))
501
- return T(t, a, 404, {
502
- status: "error",
503
- service: l.name,
504
- message: "Resource not found."
505
- });
506
- const M = g.kind === "ssr" ? g.responseCache : void 0;
507
- let L = null;
508
- try {
509
- L = await Ce(
510
- g.id,
511
- b,
512
- M
513
- );
514
- } catch (h) {
515
- d.logger?.warn?.("ssr.cache.key.failed", {
516
- entryId: g.id,
517
- requestId: b.requestId,
518
- error: h instanceof Error ? h.message : "Unknown cache error"
519
- });
520
- }
521
- if (M && L)
522
- try {
523
- const h = await M.store.get(L);
524
- if (h)
525
- return R(t, a, {
526
- ...h,
527
- headers: {
528
- ...h.headers,
529
- "server-timing": 'cache;desc="hit"'
530
- }
531
- });
532
- } catch (h) {
533
- d.logger?.warn?.("ssr.cache.read.failed", {
534
- entryId: g.id,
535
- requestId: b.requestId,
536
- error: h instanceof Error ? h.message : "Unknown cache error"
537
- });
538
- }
539
- let z = await C(l, g.template, t.url || "/");
540
- if (g.kind === "spa")
541
- return R(t, a, {
542
- statusCode: 200,
543
- body: z,
544
- headers: {
545
- "content-type": "text/html; charset=utf-8",
546
- "cache-control": g.cacheControl || "private, no-store",
547
- vary: "Host, X-Forwarded-Host",
548
- ...D
549
- }
550
- });
551
- const W = g.application;
552
- z = me(
553
- z,
554
- g.mountSelector || W.mountSelector || "#app"
555
- );
556
- const K = d.requestTimeoutMs ?? 15e3, E = await te(
557
- pe(W, b, {
558
- maxResolutionPasses: d.maxResolutionPasses,
559
- resolutionDeadlineMs: d.resolutionDeadlineMs ?? K,
560
- diagnostics: d.diagnostics ?? !e.production,
561
- logger: d.logger
562
- }),
563
- K,
564
- w
565
- );
566
- if (E.response.redirect) {
567
- const h = E.response.redirect, $ = new URL(h.location, b.url);
568
- if ($.protocol !== "http:" && $.protocol !== "https:")
569
- throw new Error("SSR redirects must use HTTP or HTTPS.");
570
- if (!h.allowExternal && $.origin !== new URL(b.url).origin)
571
- throw new Error("Cross-origin redirect requires allowExternal: true.");
572
- return R(t, a, {
573
- statusCode: h.statusCode ?? 302,
574
- headers: {
575
- location: $.href,
576
- "cache-control": "no-store"
577
- }
578
- });
579
- }
580
- const ae = fe(z, {
581
- applicationId: W.id,
582
- html: E.html,
583
- teleports: E.teleports,
584
- head: E.head,
585
- state: E.hydrationState
586
- });
587
- d.onMetrics?.(E.metrics), d.logger?.info?.("ssr.render.complete", E.metrics);
588
- const _ = {
589
- statusCode: E.response.statusCode,
590
- body: ae,
591
- headers: {
592
- "content-type": "text/html; charset=utf-8",
593
- "cache-control": g.cacheControl || "private, no-store",
594
- vary: "Host, X-Forwarded-Host",
595
- "server-timing": [
596
- `context;dur=${E.metrics.contextDurationMs.toFixed(1)}`,
597
- `route;dur=${E.metrics.routeDurationMs.toFixed(1)}`,
598
- `render;dur=${E.metrics.renderDurationMs.toFixed(1)}`
599
- ].join(", "),
600
- ...E.response.headers,
601
- ...D
602
- }
603
- };
604
- if (M && L && Pe(_, b, M))
605
- try {
606
- await M.store.set(L, _, {
607
- ttlMs: M.ttlMs,
608
- tags: await M.tags?.(b)
609
- });
610
- } catch (h) {
611
- d.logger?.warn?.("ssr.cache.write.failed", {
612
- entryId: g.id,
613
- requestId: b.requestId,
614
- error: h instanceof Error ? h.message : "Unknown cache error"
615
- });
616
- }
617
- return R(t, a, _);
618
- } catch (l) {
619
- e.vite?.ssrFixStacktrace(l);
620
- const d = await v().catch(() => o);
621
- if (d.server.logger?.error?.("ssr.request.failed", {
622
- entryId: x,
623
- pathname: c,
624
- error: l instanceof Error ? l.message : "Unknown error"
625
- }), a.writableEnded) return;
626
- if (a.headersSent) return a.destroy();
627
- const P = l instanceof se, I = P ? 504 : 500;
628
- if (d.server.renderError)
629
- try {
630
- const y = await d.server.renderError({
631
- error: l,
632
- kind: P ? "timeout" : "internal",
633
- production: e.production,
634
- request: H,
635
- entryId: x === "unknown" ? void 0 : x
636
- });
637
- if (y)
638
- return R(t, a, {
639
- ...y,
640
- statusCode: y.statusCode >= 400 ? y.statusCode : I,
641
- headers: {
642
- ...y.headers,
643
- "cache-control": "no-store",
644
- ...D
645
- }
646
- });
647
- } catch (y) {
648
- d.server.logger?.error?.("ssr.error-renderer.failed", {
649
- entryId: x,
650
- error: y instanceof Error ? y.message : "Unknown error renderer failure"
651
- });
652
- }
653
- return k(t, c) ? R(t, a, {
654
- statusCode: I,
655
- body: B(
656
- P ? "Request timed out" : "Application unavailable",
657
- e.production ? "The application could not render this page. Please try again." : l instanceof Error ? l.message : "Unknown rendering failure."
658
- ),
659
- headers: {
660
- "content-type": "text/html; charset=utf-8",
661
- "cache-control": "no-store",
662
- ...D
663
- }
664
- }) : T(t, a, I, {
665
- status: "error",
666
- service: d.name
667
- });
668
- }
669
- });
670
- return {
671
- nodeServer: S,
672
- address: () => {
673
- const t = S.address();
674
- return {
675
- host: typeof t == "object" && t ? t.address : i,
676
- port: typeof t == "object" && t ? t.port : n
677
- };
678
- },
679
- listen: () => new Promise((t, a) => {
680
- const f = (c) => a(c);
681
- S.once("error", f), S.listen(n, i, () => {
682
- S.off("error", f), Ie(
683
- i,
684
- n,
685
- s.role || "default"
686
- ), t();
687
- });
688
- }),
689
- close: async () => {
690
- if (r) return;
691
- r = !0;
692
- const t = s.shutdownTimeoutMs ?? 1e4;
693
- let a;
694
- try {
695
- await Promise.race([
696
- Promise.all([
697
- new Promise((f, c) => {
698
- S.close(
699
- (x) => x ? c(x) : f()
700
- );
701
- }),
702
- e.vite?.close()
703
- ]),
704
- new Promise((f, c) => {
705
- a = setTimeout(() => {
706
- S.closeAllConnections?.(), c(new Error("SSR server graceful shutdown timed out."));
707
- }, t);
708
- })
709
- ]);
710
- } finally {
711
- a && clearTimeout(a);
712
- }
713
- }
714
- };
715
- };
716
- export {
717
- Oe as a,
718
- ye as b,
719
- We as c,
720
- be as d,
721
- Se as e,
722
- Ee as f,
723
- xe as g,
724
- ge as h,
725
- Pe as i,
726
- Ce as j,
727
- ve as m,
728
- O as n,
729
- pe as r,
730
- V as s
731
- };