vue-ssr-lite 0.2.2 → 0.2.4

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