@withl5e/l5e 0.2.6 → 0.3.0

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