@withl5e/l5e 0.3.2 → 0.3.3-alpha.1

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/dist/server.js CHANGED
@@ -1,45 +1,46 @@
1
- import { existsSync as Q } from "fs";
2
- import H from "node:fs/promises";
1
+ import { existsSync as nt } from "fs";
2
+ import D from "node:fs/promises";
3
3
  import d from "node:path";
4
- import { pathToFileURL as I } from "node:url";
5
- import V from "request-ip";
6
- import { a as ot, s as J } from "./render-BaTAJ4Ha.js";
7
- import { c as G, p as tt, a as it } from "./index-CybB8Tdk.js";
8
- import { createHash as at } from "node:crypto";
9
- import { createRequire as ct } from "node:module";
10
- let B = null;
11
- function lt() {
12
- return B || (B = (async () => {
13
- const t = ct(import.meta.url), e = t.resolve("vite"), n = t.resolve("rollup", { paths: [d.dirname(e)] });
14
- return await import(I(n).href);
15
- })()), B;
4
+ import { pathToFileURL as N } from "node:url";
5
+ import G from "request-ip";
6
+ import { a as st, s as K } from "./render-CRag-5V7.js";
7
+ import { c as Z, p as rt, a as ct } from "./index-CybB8Tdk.js";
8
+ import { createHash as lt } from "node:crypto";
9
+ import { createRequire as ut } from "node:module";
10
+ import { r as dt } from "./global-style-DFvaBcuR.js";
11
+ let V = null;
12
+ function ft() {
13
+ return V || (V = (async () => {
14
+ const t = ut(import.meta.url), e = t.resolve("vite"), n = t.resolve("rollup", { paths: [d.dirname(e)] });
15
+ return await import(N(n).href);
16
+ })()), V;
16
17
  }
17
- const W = { hash: "", filename: "", content: "" }, z = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map();
18
- function et(t, e) {
19
- const n = K.get(t);
18
+ const J = { hash: "", filename: "", content: "" }, X = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map();
19
+ function ot(t, e) {
20
+ const n = q.get(t);
20
21
  if (n)
21
22
  return n;
22
- const s = e().catch((i) => {
23
- throw K.delete(t), i;
23
+ const s = e().catch((r) => {
24
+ throw q.delete(t), r;
24
25
  });
25
- return K.set(t, s), s;
26
+ return q.set(t, s), s;
26
27
  }
27
- function q(t) {
28
- return at("sha256").update(t).digest("hex").substring(0, 16);
28
+ function Y(t) {
29
+ return lt("sha256").update(t).digest("hex").substring(0, 16);
29
30
  }
30
- const F = "\0l5e:bundle-entry";
31
- function ut(t) {
31
+ const O = "\0l5e:bundle-entry";
32
+ function pt(t) {
32
33
  return {
33
34
  name: "l5e-virtual-entry",
34
35
  resolveId(e) {
35
- return e === F ? F : null;
36
+ return e === O ? O : null;
36
37
  },
37
38
  load(e) {
38
- return e === F ? t : null;
39
+ return e === O ? t : null;
39
40
  }
40
41
  };
41
42
  }
42
- function dt(t) {
43
+ function ht(t) {
43
44
  const e = (n) => "/" + d.relative(t, n).replace(/\\/g, "/");
44
45
  return {
45
46
  name: "vendor-path-rewriter",
@@ -48,138 +49,138 @@ function dt(t) {
48
49
  }
49
50
  };
50
51
  }
51
- async function ft(t, e) {
52
- const n = t.map((u) => {
53
- const k = u.startsWith("/") ? d.join(e, u.substring(1)) : d.join(e, u);
54
- return `import ${JSON.stringify(k)};`;
52
+ async function mt(t, e) {
53
+ const n = t.map((a) => {
54
+ const _ = a.startsWith("/") ? d.join(e, a.substring(1)) : d.join(e, a);
55
+ return `import ${JSON.stringify(_)};`;
55
56
  }).join(`
56
57
  `), s = {
57
- input: F,
58
- plugins: [ut(n), dt(e)],
59
- external: (u) => !u.startsWith(".") && !d.isAbsolute(u) && u !== F
60
- }, i = {
58
+ input: O,
59
+ plugins: [pt(n), ht(e)],
60
+ external: (a) => !a.startsWith(".") && !d.isAbsolute(a) && a !== O
61
+ }, r = {
61
62
  format: "es",
62
63
  inlineDynamicImports: !1,
63
64
  entryFileNames: "bundle-[hash].js",
64
65
  chunkFileNames: "bundle-[hash].js"
65
- }, { rollup: l } = await lt(), c = await l(s);
66
- let a;
66
+ }, { rollup: l } = await ft(), w = await l(s);
67
+ let f;
67
68
  try {
68
- ({ output: a } = await c.generate(i));
69
+ ({ output: f } = await w.generate(r));
69
70
  } finally {
70
- await c.close();
71
+ await w.close();
71
72
  }
72
- for (const u of a)
73
- u.type === "chunk" && z.set(u.fileName, {
74
- content: u.code || "",
75
- hash: q(u.code || ""),
76
- filename: u.fileName,
73
+ for (const a of f)
74
+ a.type === "chunk" && X.set(a.fileName, {
75
+ content: a.code || "",
76
+ hash: Y(a.code || ""),
77
+ filename: a.fileName,
77
78
  mimeType: "application/javascript"
78
79
  });
79
- const f = a[0];
80
- if (f?.type !== "chunk")
80
+ const o = f[0];
81
+ if (o?.type !== "chunk")
81
82
  throw new Error("[bundler] rollup produced no entry chunk");
82
83
  return {
83
- hash: q(f.code || ""),
84
- filename: f.fileName,
85
- content: f.code || ""
84
+ hash: Y(o.code || ""),
85
+ filename: o.fileName,
86
+ content: o.code || ""
86
87
  };
87
88
  }
88
- async function pt(t, e) {
89
+ async function wt(t, e) {
89
90
  if (t.length === 0)
90
- return W;
91
+ return J;
91
92
  const n = [...new Set(t)].sort(), s = `scripts:${n.join(",")}`;
92
93
  try {
93
- return await et(s, () => ft(n, e));
94
- } catch (i) {
95
- return console.error("[bundler] Error bundling scripts:", i), W;
94
+ return await ot(s, () => mt(n, e));
95
+ } catch (r) {
96
+ return console.error("[bundler] Error bundling scripts:", r), J;
96
97
  }
97
98
  }
98
- async function ht(t, e) {
99
+ async function gt(t, e) {
99
100
  const n = [];
100
- for (const c of t) {
101
- const a = c.startsWith("/") ? d.join(e, c.substring(1)) : d.join(e, c);
101
+ for (const w of t) {
102
+ const f = w.startsWith("/") ? d.join(e, w.substring(1)) : d.join(e, w);
102
103
  try {
103
- const f = await H.readFile(a, "utf-8");
104
- n.push(`/* ${c} */
105
- ${f}
104
+ const o = await D.readFile(f, "utf-8");
105
+ n.push(`/* ${w} */
106
+ ${o}
106
107
  `);
107
- } catch (f) {
108
- console.warn(`[bundler] Failed to read CSS file: ${c}`, f);
108
+ } catch (o) {
109
+ console.warn(`[bundler] Failed to read CSS file: ${w}`, o);
109
110
  }
110
111
  }
111
112
  const s = n.join(`
112
113
 
113
- `), i = q(s), l = `bundle-${i}.css`;
114
- return z.set(l, {
114
+ `), r = Y(s), l = `bundle-${r}.css`;
115
+ return X.set(l, {
115
116
  content: s,
116
- hash: i,
117
+ hash: r,
117
118
  filename: l,
118
119
  mimeType: "text/css"
119
- }), { hash: i, filename: l, content: s };
120
+ }), { hash: r, filename: l, content: s };
120
121
  }
121
- async function mt(t, e) {
122
+ async function yt(t, e) {
122
123
  if (t.length === 0)
123
- return W;
124
+ return J;
124
125
  const n = [...new Set(t)].sort(), s = `css:${n.join(",")}`;
125
126
  try {
126
- return await et(s, () => ht(n, e));
127
- } catch (i) {
128
- return console.error("[bundler] Error bundling CSS:", i), W;
127
+ return await ot(s, () => gt(n, e));
128
+ } catch (r) {
129
+ return console.error("[bundler] Error bundling CSS:", r), J;
129
130
  }
130
131
  }
131
- function wt(t) {
132
- return z.get(t);
132
+ function bt(t) {
133
+ return X.get(t);
133
134
  }
134
- function gt(t, e) {
135
- const n = ot(e);
136
- return t.replace(/<html\b([^>]*)>/i, (s, i) => /\blang\s*=/i.test(i) ? s.replace(/lang\s*=\s*"[^"]*"/i, () => `lang="${n}"`) : `<html lang="${n}"${i}>`);
135
+ function vt(t, e) {
136
+ const n = st(e);
137
+ return t.replace(/<html\b([^>]*)>/i, (s, r) => /\blang\s*=/i.test(r) ? s.replace(/lang\s*=\s*"[^"]*"/i, () => `lang="${n}"`) : `<html lang="${n}"${r}>`);
137
138
  }
138
- function yt(t) {
139
+ function St(t) {
139
140
  return new URL(`${t.protocol}://${t.get("host")}${t.originalUrl}`);
140
141
  }
141
- function nt(t, e) {
142
+ function it(t, e) {
142
143
  return `${t.pathname}${t.search}`.replace(e, "") || "/";
143
144
  }
144
- function Y(t) {
145
+ function Q(t) {
145
146
  const e = {
146
147
  method: t.method,
147
- headers: it(t)
148
+ headers: ct(t)
148
149
  };
149
- return t.method !== "GET" && t.method !== "HEAD" && (e.body = t, e.duplex = "half"), new globalThis.Request(yt(t).href, e);
150
+ return t.method !== "GET" && t.method !== "HEAD" && (e.body = t, e.duplex = "half"), new globalThis.Request(St(t).href, e);
150
151
  }
151
- function D(t, e, n, s) {
152
- const i = new URL(e.url), l = nt(i, n), c = l.startsWith("/") ? l : `/${l}`, a = {};
153
- return e.headers.forEach((f, u) => {
154
- a[u] = f;
152
+ function z(t, e, n, s) {
153
+ const r = new URL(e.url), l = it(r, n), w = l.startsWith("/") ? l : `/${l}`, f = {};
154
+ return e.headers.forEach((o, a) => {
155
+ f[a] = o;
155
156
  }), {
156
- url: i,
157
- path: c,
158
- pathname: i.pathname,
157
+ url: r,
158
+ path: w,
159
+ pathname: r.pathname,
159
160
  method: e.method,
160
- headers: a,
161
- cookies: tt(e.headers.get("cookie") ?? void 0),
162
- query: Object.fromEntries(i.searchParams.entries()),
163
- ip: V.getClientIp(t) ?? void 0,
161
+ headers: f,
162
+ cookies: rt(e.headers.get("cookie") ?? void 0),
163
+ query: Object.fromEntries(r.searchParams.entries()),
164
+ ip: G.getClientIp(t) ?? void 0,
164
165
  locals: s
165
166
  };
166
167
  }
167
- function X(t, e, n) {
168
+ function tt(t, e, n) {
168
169
  return t ? t instanceof globalThis.Request ? t : t instanceof URL ? new globalThis.Request(t.href, e.clone()) : new globalThis.Request(new URL(t, n).href, e.clone()) : e;
169
170
  }
170
- async function Z(t, e, n) {
171
+ async function et(t, e, n) {
171
172
  e.status(n.status);
172
- const s = bt(n.headers);
173
- if (n.headers.forEach((l, c) => {
174
- c.toLowerCase() !== "set-cookie" && e.setHeader(c, l);
173
+ const s = xt(n.headers);
174
+ if (n.headers.forEach((l, w) => {
175
+ w.toLowerCase() !== "set-cookie" && e.setHeader(w, l);
175
176
  }), s.length > 0 && e.setHeader("Set-Cookie", s), t.method === "HEAD") {
176
177
  e.end();
177
178
  return;
178
179
  }
179
- const i = Buffer.from(await n.arrayBuffer());
180
- e.send(i);
180
+ const r = Buffer.from(await n.arrayBuffer());
181
+ e.send(r);
181
182
  }
182
- function bt(t) {
183
+ function xt(t) {
183
184
  const e = t.getSetCookie;
184
185
  if (typeof e == "function")
185
186
  return e.call(t);
@@ -187,38 +188,39 @@ function bt(t) {
187
188
  if (n?.["set-cookie"])
188
189
  return n["set-cookie"];
189
190
  const s = t.get("set-cookie");
190
- return s ? vt(s) : [];
191
+ return s ? $t(s) : [];
191
192
  }
192
- function vt(t) {
193
+ function $t(t) {
193
194
  const e = [];
194
195
  let n = 0;
195
196
  for (let s = 0; s < t.length; s++) {
196
197
  if (t[s] !== ",") continue;
197
- const i = t.slice(s + 1);
198
- /^\s*[^=;,]+=/.test(i) && (e.push(t.slice(n, s).trim()), n = s + 1);
198
+ const r = t.slice(s + 1);
199
+ /^\s*[^=;,]+=/.test(r) && (e.push(t.slice(n, s).trim()), n = s + 1);
199
200
  }
200
201
  return e.push(t.slice(n).trim()), e.filter(Boolean);
201
202
  }
202
- function St(t) {
203
+ function Rt(t) {
203
204
  if (!t.rawResponse)
204
205
  return null;
205
- const { body: e, contentType: n, statusCode: s, headers: i } = t.rawResponse, l = new Headers(i);
206
+ const { body: e, contentType: n, statusCode: s, headers: r } = t.rawResponse, l = new Headers(r);
206
207
  return l.set("Content-Type", n), new globalThis.Response(e, {
207
208
  status: s || 200,
208
209
  headers: l
209
210
  });
210
211
  }
211
- async function xt({
212
+ async function Ct({
212
213
  rendered: t,
213
214
  template: e,
214
215
  manifest: n,
215
216
  root: s,
216
- distClientDir: i,
217
- isProduction: l
217
+ distClientDir: r,
218
+ isProduction: l,
219
+ assetBase: w
218
220
  }) {
219
- const c = St(t);
220
- if (c)
221
- return c;
221
+ const f = Rt(t);
222
+ if (f)
223
+ return f;
222
224
  if (t.redirect)
223
225
  return new globalThis.Response(null, {
224
226
  status: t.redirect.statusCode,
@@ -226,103 +228,117 @@ async function xt({
226
228
  Location: t.redirect.url
227
229
  }
228
230
  });
229
- let a = t.scripts || [], f = t.styles || [];
230
- const u = t.islands || [];
231
- let k = t.cacheTags || [];
232
- const _ = t.maxAge, N = t.sMaxAge, U = t.swr;
233
- let o = "", p = [], w = "";
234
- if (l && n) {
235
- let x = function(r) {
236
- const m = n[r];
237
- return m ? (m.css && m.css.forEach((v) => g.add(v)), m.imports && m.imports.forEach((v) => {
238
- const P = n[v];
239
- P?.file && T.add(P.file), P?.css && P.css.forEach((A) => g.add(A)), P?.imports && P.imports.forEach((A) => {
240
- const j = n[A];
241
- j?.file && T.add(j.file), j?.css && j.css.forEach((O) => g.add(O));
231
+ let o = t.scripts || [], a = t.styles || [];
232
+ const _ = t.islands || [];
233
+ let P = t.cacheTags || [];
234
+ const H = t.maxAge, W = t.sMaxAge, B = t.swr;
235
+ let i = "";
236
+ const p = /* @__PURE__ */ new Set(), g = (S, C = !1) => {
237
+ p.has(S) || (p.add(S), i += `<link rel="stylesheet"${C ? " crossorigin" : ""} href="${st(S)}">`);
238
+ };
239
+ let v = [], $ = "";
240
+ const x = dt({
241
+ root: s,
242
+ manifest: n,
243
+ isProduction: l,
244
+ base: w
245
+ });
246
+ x && g(x, l);
247
+ let j = "";
248
+ if (t.islandData && t.islandData.length > 0 && (j = `<script type="application/json" id="_l5e_data_">${K(
249
+ t.islandData,
250
+ { isJSON: !0 }
251
+ )}<\/script>`), l && n) {
252
+ let S = function(c) {
253
+ const h = n[c];
254
+ return h ? (h.css && h.css.forEach((m) => C.add(m)), h.imports && h.imports.forEach((m) => {
255
+ const M = n[m];
256
+ M?.file && y.add(M.file), M?.css && M.css.forEach((U) => C.add(U)), M?.imports && M.imports.forEach((U) => {
257
+ const F = n[U];
258
+ F?.file && y.add(F.file), F?.css && F.css.forEach((at) => C.add(at));
242
259
  });
243
- }), { file: m.file }) : { file: null };
260
+ }), { file: h.file }) : { file: null };
244
261
  };
245
- a = a.filter((r) => !r.includes(".global.")), f = f.filter((r) => !r.includes(".global."));
246
- const g = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), M = [];
247
- for (const r of a) {
248
- const m = r.replace(/^\//, ""), { file: v } = x(m);
249
- v && M.push(`/${v}`);
262
+ o = o.filter((c) => !c.includes(".global.")), a = a.filter((c) => !c.includes(".global."));
263
+ const C = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Set(), u = [];
264
+ for (const c of o) {
265
+ const h = c.replace(/^\//, ""), { file: m } = S(h);
266
+ m && u.push(`/${m}`);
250
267
  }
251
- const L = [];
252
- for (const r of f) {
253
- const m = r.replace(/^\//, ""), { file: v } = x(m);
254
- v && (L.push(`/${v}`), g.add(v));
268
+ const A = [];
269
+ for (const c of a) {
270
+ const h = c.replace(/^\//, ""), { file: m } = S(h);
271
+ m && (A.push(`/${m}`), C.add(m));
255
272
  }
256
- if (M.length > 0) {
257
- const r = await pt(M, i);
258
- a = r.filename ? [`/${r.filename}`] : M;
273
+ if (u.length > 0) {
274
+ const c = await wt(u, r);
275
+ o = c.filename ? [`/${c.filename}`] : u;
259
276
  }
260
- if (L.length > 0) {
261
- const r = await mt(L, i);
262
- r.filename && (f = [`/${r.filename}`]);
277
+ if (A.length > 0) {
278
+ const c = await yt(A, r);
279
+ c.filename && (a = [`/${c.filename}`]);
263
280
  }
264
- const h = n["src/client.global.ts"];
265
- if (h && (h.css && h.css.length > 0 && h.css.forEach((r) => {
266
- o += `<link rel="stylesheet" crossorigin href="/${r}">`;
267
- }), h.file && p.push(`/${h.file}`)), u.length > 0) {
268
- const r = {};
269
- for (const m of u) {
270
- const v = n[m.src];
271
- v?.file && (r[m.key] = `/${v.file}`);
281
+ const T = n["src/client.global.ts"];
282
+ if (T && (T.css && T.css.length > 0 && T.css.forEach((c) => {
283
+ g(`/${c}`, !0);
284
+ }), T.file && v.push(`/${T.file}`)), _.length > 0) {
285
+ const c = {};
286
+ for (const h of _) {
287
+ const m = n[h.src];
288
+ m?.file && (c[h.key] = `/${m.file}`);
272
289
  }
273
- Object.keys(r).length > 0 && (w = `<script>window.__L5E_ISLANDS__=${J(r)}<\/script>`);
290
+ Object.keys(c).length > 0 && ($ = `<script>window.__L5E_ISLANDS__=${K(c)}<\/script>`);
274
291
  }
275
- f.length > 0 && (o += f.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
292
+ a.length > 0 && a.forEach((c) => g(c, !0));
276
293
  }
277
- let y = "";
278
- l || (y = [...new Set(f)].map((x) => `<link rel="stylesheet" href="${x}">`).join(""));
279
- let b = [...p, ...a];
294
+ l || [...new Set(a)].forEach((S) => g(S));
295
+ let b = [...v, ...o];
280
296
  if (!l) {
281
- const x = d.join(s, "src", "client.global.ts");
282
- if (Q(x) && (b = ["/src/client.global.ts", ...b]), b = [...new Set(b)], u.length > 0) {
283
- const g = {};
284
- for (const T of u)
285
- g[T.key] = `/${T.src}`;
286
- w = `<script>window.__L5E_ISLANDS__=${J(g)}<\/script>`;
297
+ const S = d.join(s, "src", "client.global.ts");
298
+ if (nt(S) && (b = ["/src/client.global.ts", ...b]), b = [...new Set(b)], _.length > 0) {
299
+ const C = {};
300
+ for (const y of _)
301
+ C[y.key] = `/${y.src}`;
302
+ $ = `<script>window.__L5E_ISLANDS__=${K(C)}<\/script>`;
287
303
  }
288
304
  }
289
- const S = w + b.map((x) => `<script type="module" src="${x}"><\/script>`).join(""), E = t.lang ? gt(e, t.lang) : e, $ = t.rawHtml ? t.html || "" : E.replace("<!--app-head-->", () => (t.head ?? "") + o + y).replace("<!--app-html-->", () => t.html ?? "").replace("<!--app-scripts-->", () => S), C = new Headers({
305
+ const L = j + $ + b.map((S) => `<script type="module" src="${S}"><\/script>`).join(""), E = t.lang ? vt(e, t.lang) : e, I = t.rawHtml ? t.html || "" : E.replace("<!--app-head-->", () => (t.head ?? "") + i).replace("<!--app-html-->", () => t.html ?? "").replace("<!--app-scripts-->", () => L), R = new Headers({
290
306
  "Content-Type": "text/html"
291
- }), R = ["public"];
292
- return _ !== void 0 && R.push(`max-age=${_}`), N !== void 0 && R.push(`s-maxage=${N}`), U !== void 0 && R.push(`stale-while-revalidate=${U}`), R.length > 1 && l && C.set("Cache-Control", R.join(", ")), process.env.NODE_ENV === "production" && (k = Ct(k)), C.set("Cache-Tag", ["global", ...k].join(",")), new globalThis.Response($, {
307
+ }), k = ["public"];
308
+ return H !== void 0 && k.push(`max-age=${H}`), W !== void 0 && k.push(`s-maxage=${W}`), B !== void 0 && k.push(`stale-while-revalidate=${B}`), k.length > 1 && l && R.set("Cache-Control", k.join(", ")), process.env.NODE_ENV === "production" && (P = kt(P)), R.set("Cache-Tag", ["global", ...P].join(",")), new globalThis.Response(I, {
293
309
  status: t.statusCode || 200,
294
- headers: C
310
+ headers: R
295
311
  });
296
312
  }
297
- async function $t(t = {}) {
298
- const e = t.root || process.cwd(), n = t.base || "/", s = process.env.NODE_ENV === "production", i = s ? await H.readFile(d.join(e, "./index.html"), "utf-8") : "", l = (await import("express")).default, c = t.app || l();
313
+ async function jt(t = {}) {
314
+ const e = t.root || process.cwd(), n = t.base || "/", s = process.env.NODE_ENV === "production", r = t.externalizeIslandProps ?? !0, l = s ? await D.readFile(d.join(e, "./index.html"), "utf-8") : "", w = (await import("express")).default, f = t.app || w();
299
315
  if (t.publicDir) {
300
- const o = d.isAbsolute(t.publicDir) ? t.publicDir : d.join(e, t.publicDir);
301
- Q(o) && c.use(l.static(o));
316
+ const i = d.isAbsolute(t.publicDir) ? t.publicDir : d.join(e, t.publicDir);
317
+ nt(i) && f.use(w.static(i));
302
318
  }
303
- let a;
304
- const f = d.join(e, "./dist/client");
319
+ let o;
320
+ const a = d.join(e, "./dist/client");
305
321
  if (s) {
306
- const o = (await import("compression")).default, p = (await import("sirv")).default;
307
- c.use(o()), c.use(n, p(f, { extensions: [] })), c.get(
322
+ const i = (await import("compression")).default, p = (await import("sirv")).default;
323
+ f.use(i()), f.use(n, p(a, { extensions: [] })), f.get(
308
324
  `${n === "/" ? "" : n}/bundle-:hash.:ext`,
309
- async (w, y) => {
325
+ async (g, v) => {
310
326
  try {
311
- const { hash: b, ext: S } = w.params, E = `bundle-${b}.${S}`, $ = wt(E);
312
- if (!$)
313
- return y.status(404).send("Bundled file not found");
314
- y.set({
315
- "Content-Type": $.mimeType,
327
+ const { hash: $, ext: x } = g.params, j = `bundle-${$}.${x}`, b = bt(j);
328
+ if (!b)
329
+ return v.status(404).send("Bundled file not found");
330
+ v.set({
331
+ "Content-Type": b.mimeType,
316
332
  "Cache-Control": "public, max-age=31536000, immutable"
317
- }), y.send($.content);
318
- } catch (b) {
319
- console.error("[server] Error serving bundled file:", b), y.status(500).end("Internal server error");
333
+ }), v.send(b.content);
334
+ } catch ($) {
335
+ console.error("[server] Error serving bundled file:", $), v.status(500).end("Internal server error");
320
336
  }
321
337
  }
322
338
  );
323
339
  } else {
324
- const { createServer: o } = await import("vite"), p = d.join(e, "vite.config.js");
325
- a = await o({
340
+ const { createServer: i } = await import("vite"), p = d.join(e, "vite.config.js");
341
+ o = await i({
326
342
  root: e,
327
343
  configFile: p,
328
344
  server: { middlewareMode: !0 },
@@ -339,141 +355,144 @@ async function $t(t = {}) {
339
355
  resolve: {
340
356
  conditions: ["development", "default"]
341
357
  }
342
- }), c.use(a.middlewares);
358
+ }), f.use(o.middlewares);
343
359
  }
344
- c.use("/_l5e/action", l.json({ limit: "100kb" }));
345
- const u = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
346
- let k = null, _ = null;
347
- async function N() {
360
+ f.use("/_l5e/action", w.json({ limit: "100kb" }));
361
+ const _ = /^[a-zA-Z]\w+_[0-9a-f]{1,4}$/;
362
+ let P = null, H = null;
363
+ async function W() {
348
364
  if (!s)
349
- return (await a.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
350
- if (!k) {
351
- const o = d.join(e, "./dist/server/action-registry.json"), p = await H.readFile(o, "utf-8");
352
- k = JSON.parse(p);
365
+ return (await o.ssrLoadModule("virtual:l5e-actions")).actionRegistry || {};
366
+ if (!P) {
367
+ const i = d.join(e, "./dist/server/action-registry.json"), p = await D.readFile(i, "utf-8");
368
+ P = JSON.parse(p);
353
369
  }
354
- return k;
370
+ return P;
355
371
  }
356
- async function U() {
372
+ async function B() {
357
373
  if (!s)
358
- return (await a.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
359
- if (!_) {
360
- const o = d.join(e, "./dist/server/entry-server.js");
361
- _ = (await import(I(o).href)).viewActions || {};
374
+ return (await o.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
375
+ if (!H) {
376
+ const i = d.join(e, "./dist/server/entry-server.js");
377
+ H = (await import(N(i).href)).viewActions || {};
362
378
  }
363
- return _;
379
+ return H;
364
380
  }
365
- return c.all("/_l5e/action/:actionKey", async (o, p) => {
381
+ return f.all("/_l5e/action/:actionKey", async (i, p) => {
366
382
  try {
367
- const { actionKey: w } = o.params;
368
- if (!u.test(w))
383
+ const { actionKey: g } = i.params;
384
+ if (!_.test(g))
369
385
  return p.status(400).send("Invalid action key");
370
- const b = (await N())[w];
371
- if (!b)
386
+ const $ = (await W())[g];
387
+ if (!$)
372
388
  return p.status(404).send("Action not found");
373
- const { modulePath: S, actionName: E } = b;
374
- let $;
389
+ const { modulePath: x, actionName: j } = $;
390
+ let b;
375
391
  if (s) {
376
- const A = await U(), j = A[`/src/${S}/actions.tsx`] ? `/src/${S}/actions.tsx` : A[`/src/${S}/actions.ts`] ? `/src/${S}/actions.ts` : null;
377
- if (!j)
392
+ const h = await B(), m = h[`/src/${x}/actions.tsx`] ? `/src/${x}/actions.tsx` : h[`/src/${x}/actions.ts`] ? `/src/${x}/actions.ts` : null;
393
+ if (!m)
378
394
  return p.status(404).send("Action module not found");
379
- $ = await A[j]();
395
+ b = await h[m]();
380
396
  } else
381
397
  try {
382
- $ = await a.ssrLoadModule(`/src/${S}/actions.tsx`);
398
+ b = await o.ssrLoadModule(`/src/${x}/actions.tsx`);
383
399
  } catch {
384
- $ = await a.ssrLoadModule(`/src/${S}/actions.ts`);
400
+ b = await o.ssrLoadModule(`/src/${x}/actions.ts`);
385
401
  }
386
- if (!Object.prototype.hasOwnProperty.call($, E))
402
+ if (!Object.prototype.hasOwnProperty.call(b, j))
387
403
  return p.status(404).send("Action not found");
388
- const C = $[E];
389
- if (!C || !C.handler)
404
+ const L = b[j];
405
+ if (!L || !L.handler)
390
406
  return p.status(404).send("Action not found");
391
- const R = (C.method || "GET").toUpperCase();
392
- if (o.method.toUpperCase() !== R)
393
- return p.status(405).set("Allow", R).send("Method Not Allowed");
394
- const x = d.join(e, "./dist/server/entry-server.js"), g = s ? await import(I(x).href) : await a.ssrLoadModule("@withl5e/l5e/entry-server"), { runInRenderContext: T } = await (s ? import(I(x).href) : a.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: M } = await (s ? import(I(x).href) : a.ssrLoadModule("@withl5e/l5e")), L = {}, h = Y(o), r = G({
395
- request: h,
396
- locals: L,
397
- clientAddress: V.getClientIp(o) ?? void 0
398
- }), m = await g.loadMiddleware?.(), P = await (typeof m == "function" ? m : (A, j) => j())(r, async (A) => {
399
- const j = X(A, r.request, r.url), O = {
400
- ...D(o, j, n, L),
401
- path: o.originalUrl,
402
- body: o.body
403
- }, st = await T(
407
+ const E = (L.method || "GET").toUpperCase();
408
+ if (i.method.toUpperCase() !== E)
409
+ return p.status(405).set("Allow", E).send("Method Not Allowed");
410
+ const I = d.join(e, "./dist/server/entry-server.js"), R = s ? await import(N(I).href) : await o.ssrLoadModule("@withl5e/l5e/entry-server"), { runInRenderContext: k } = await (s ? import(N(I).href) : o.ssrLoadModule("@withl5e/l5e/jsx-runtime")), { renderJsxToHtmlString: S } = await (s ? import(N(I).href) : o.ssrLoadModule("@withl5e/l5e")), C = {}, y = Q(i), u = Z({
411
+ request: y,
412
+ locals: C,
413
+ clientAddress: G.getClientIp(i) ?? void 0
414
+ }), A = await R.loadMiddleware?.(), c = await (typeof A == "function" ? A : (h, m) => m())(u, async (h) => {
415
+ const m = tt(h, u.request, u.url), M = {
416
+ ...z(i, m, n, C),
417
+ path: i.originalUrl,
418
+ body: i.body
419
+ }, U = await k(
404
420
  async () => {
405
- const rt = await C.handler(O);
406
- return M(rt);
421
+ const F = await L.handler(M);
422
+ return S(F);
407
423
  },
408
- O,
409
- S
424
+ M,
425
+ x
410
426
  );
411
- return new Response(st, { headers: { "Content-Type": "text/html" } });
427
+ return new Response(U, { headers: { "Content-Type": "text/html" } });
412
428
  });
413
- await Z(o, p, P);
414
- } catch (w) {
415
- a?.ssrFixStacktrace?.(w), console.error("[l5e] Action error:", w.stack || w), p.status(500).send("Internal server error");
429
+ await et(i, p, c);
430
+ } catch (g) {
431
+ o?.ssrFixStacktrace?.(g), console.error("[l5e] Action error:", g.stack || g), p.status(500).send("Internal server error");
416
432
  }
417
- }), c.use(async (o, p) => {
433
+ }), f.use(async (i, p) => {
418
434
  try {
419
- const w = o.originalUrl.replace(n, "");
420
- let y, b, S, E;
435
+ const g = i.originalUrl.replace(n, "");
436
+ let v, $, x, j;
421
437
  if (s) {
422
- y = i;
423
- const h = d.join(e, "./dist/server/entry-server.js"), r = await import(I(h).href);
424
- b = r.render, S = r.loadMiddleware;
425
- const m = await H.readFile(
438
+ v = l;
439
+ const y = d.join(e, "./dist/server/entry-server.js"), u = await import(N(y).href);
440
+ $ = u.render, x = u.loadMiddleware;
441
+ const A = await D.readFile(
426
442
  d.join(e, "./dist/client/.vite/manifest.json"),
427
443
  "utf-8"
428
444
  );
429
- E = JSON.parse(m);
445
+ j = JSON.parse(A);
430
446
  } else {
431
- y = await H.readFile(d.join(e, "./index.html"), "utf-8"), y = await a.transformIndexHtml(w, y), y.includes("@vite/client") || (y = y.replace(
447
+ v = await D.readFile(d.join(e, "./index.html"), "utf-8"), v = await o.transformIndexHtml(g, v), v.includes("@vite/client") || (v = v.replace(
432
448
  "</head>",
433
449
  '<script type="module" src="/@vite/client"><\/script></head>'
434
450
  ));
435
- const h = await a.ssrLoadModule(
451
+ const y = await o.ssrLoadModule(
436
452
  "@withl5e/l5e/entry-server"
437
453
  );
438
- b = h.render, S = h.loadMiddleware;
454
+ $ = y.render, x = y.loadMiddleware;
439
455
  }
440
- const $ = await S?.(), C = typeof $ == "function" ? $ : (h, r) => r(), R = {}, x = Y(o), g = G({
441
- request: x,
442
- requestInfo: D(o, x, n, R),
443
- locals: R,
444
- clientAddress: V.getClientIp(o)
445
- }), T = async (h) => {
446
- const r = D(o, h, n, R), m = nt(r.url, n), v = await b(m, r);
447
- return xt({
448
- rendered: v,
449
- template: y,
450
- manifest: E,
456
+ const b = await x?.(), L = typeof b == "function" ? b : (y, u) => u(), E = {}, I = Q(i), R = Z({
457
+ request: I,
458
+ requestInfo: z(i, I, n, E),
459
+ locals: E,
460
+ clientAddress: G.getClientIp(i)
461
+ }), k = async (y) => {
462
+ const u = z(i, y, n, E), A = it(u.url, n), T = await $(A, u, {
463
+ externalizeIslandProps: r
464
+ });
465
+ return Ct({
466
+ rendered: T,
467
+ template: v,
468
+ manifest: j,
451
469
  root: e,
452
- distClientDir: f,
453
- isProduction: s
470
+ distClientDir: a,
471
+ isProduction: s,
472
+ assetBase: s ? n : o.config.base
454
473
  });
455
- }, M = async (h) => {
456
- const r = X(h, g.request, g.url);
457
- return g.request = r, g.url = new URL(r.url), g.cookies = tt(r.headers.get("cookie") ?? void 0), g.requestInfo = D(o, r, n, R), T(r);
474
+ }, S = async (y) => {
475
+ const u = tt(y, R.request, R.url);
476
+ return R.request = u, R.url = new URL(u.url), R.cookies = rt(u.headers.get("cookie") ?? void 0), R.requestInfo = z(i, u, n, E), k(u);
458
477
  };
459
- g.rewrite = (h) => M(h);
460
- const L = await C(g, M);
461
- await Z(o, p, L);
462
- } catch (w) {
463
- a?.ssrFixStacktrace?.(w), console.error(w.stack), p.status(500).end(s ? "Internal Server Error" : w.stack);
478
+ R.rewrite = (y) => S(y);
479
+ const C = await L(R, S);
480
+ await et(i, p, C);
481
+ } catch (g) {
482
+ o?.ssrFixStacktrace?.(g), console.error(g.stack), p.status(500).end(s ? "Internal Server Error" : g.stack);
464
483
  }
465
- }), { app: c, vite: a };
484
+ }), { app: f, vite: o };
466
485
  }
467
- async function Ht(t = {}) {
486
+ async function Dt(t = {}) {
468
487
  const e = t.port || 5173, n = (await import("express")).default, s = n();
469
488
  t.setupApp && (console.log("setupApp"), await t.setupApp(s));
470
- const { app: i } = await $t({ ...t, app: s });
471
- i.listen(e, () => {
489
+ const { app: r } = await jt({ ...t, app: s });
490
+ r.listen(e, () => {
472
491
  console.log(`Server started at http://localhost:${e}`);
473
492
  });
474
493
  }
475
- const Rt = 1e3;
476
- function jt(t) {
494
+ const At = 1e3;
495
+ function Et(t) {
477
496
  if (t === "global")
478
497
  return "global";
479
498
  let e = 0;
@@ -483,14 +502,14 @@ function jt(t) {
483
502
  }
484
503
  return Math.abs(e).toString(36).substring(0, 8);
485
504
  }
486
- function Ct(t) {
487
- return (Array.isArray(t) ? t : [...t]).slice(0, Rt).map(jt);
505
+ function kt(t) {
506
+ return (Array.isArray(t) ? t : [...t]).slice(0, At).map(Et);
488
507
  }
489
508
  export {
490
- gt as applyHtmlLang,
491
- $t as createServer,
492
- jt as hashTag,
493
- Ct as optimizeCacheTags,
494
- Ht as startServer
509
+ vt as applyHtmlLang,
510
+ jt as createServer,
511
+ Et as hashTag,
512
+ kt as optimizeCacheTags,
513
+ Dt as startServer
495
514
  };
496
515
  //# sourceMappingURL=server.js.map