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