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