@withl5e/l5e 0.2.7 → 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 G } from "fs";
2
- import M from "node:fs/promises";
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;
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 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 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 se(e, t, n) {
22
- if (e.length === 0)
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);
27
- if (a)
28
- return {
29
- hash: a.hash,
30
- filename: a.filename,
31
- content: a.content
32
- };
33
- }
34
- let c = 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 = U(o.join(`
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)};`;
43
- }).join(`
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,
48
- plugins: [
49
- {
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(".")) {
56
- console.log(
57
- `[bundler] Resolving relative path: ${s} from importer: ${h}`
58
- );
59
- const y = u.resolve(u.dirname(h), s);
60
- return { id: "/" + u.relative(n, y).replace(/\\/g, "/"), external: !0 };
61
- } else
62
- console.log(`[bundler] Resolving source: ${s}`);
63
- }
64
- return null;
65
- }
66
- }
67
- ],
68
- external: (s) => !s.startsWith(".") && !u.isAbsolute(s) ? !0 : (s.includes("vendor-") || s.includes("chunk-") || s.includes(".global"), !1)
69
- }, j = {
70
- format: "es",
71
- inlineDynamicImports: !1,
72
- entryFileNames: "bundle-[hash].js",
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")
77
- return;
78
- const h = {
79
- content: s.code || "",
80
- hash: U(s.code || ""),
81
- filename: s.fileName,
82
- mimeType: "application/javascript"
83
- };
84
- I.set(s.fileName, h);
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 || ""
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
- c && await M.unlink(c).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 oe(e, t, n) {
100
- if (e.length === 0)
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)
106
- return {
107
- hash: c.hash,
108
- filename: c.filename,
109
- content: c.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 c = [];
114
- for (const j of o) {
115
- const P = j.startsWith("/") ? u.join(n, j.substring(1)) : u.join(n, j);
116
- try {
117
- const C = await M.readFile(P, "utf-8");
118
- c.push(`/* ${j} */
119
- ${C}
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 (C) {
122
- console.warn(`[bundler] Failed to read CSS file: ${j}`, C);
123
- }
107
+ } catch (f) {
108
+ console.warn(`[bundler] Failed to read CSS file: ${c}`, f);
124
109
  }
125
- const a = c.join(`
110
+ }
111
+ const s = n.join(`
126
112
 
127
- `), g = U(a), $ = `bundle-${g}.css`, R = {
128
- content: a,
129
- hash: g,
130
- filename: $,
131
- mimeType: "text/css"
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: "" };
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 re(e) {
139
- return I.get(e);
131
+ function wt(t) {
132
+ return z.get(t);
140
133
  }
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}>`);
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 ae(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 X(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 ce(e) {
152
- const t = {
153
- method: e.method,
154
- headers: q(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(ae(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 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;
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: l,
156
+ url: i,
164
157
  path: c,
165
- pathname: l.pathname,
166
- method: t.method,
158
+ pathname: i.pathname,
159
+ method: e.method,
167
160
  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
161
+ cookies: tt(e.headers.get("cookie") ?? void 0),
162
+ query: Object.fromEntries(i.searchParams.entries()),
163
+ ip: V.getClientIp(t) ?? void 0,
164
+ locals: s
172
165
  };
173
166
  }
174
- function le(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 ue(e, t, n) {
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") {
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 l = Buffer.from(await n.arrayBuffer());
187
- t.send(l);
179
+ const i = Buffer.from(await n.arrayBuffer());
180
+ e.send(i);
188
181
  }
189
- function fe(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 o = e.get("set-cookie");
197
- return o ? he(o) : [];
189
+ const s = t.get("set-cookie");
190
+ return s ? vt(s) : [];
198
191
  }
199
- function he(e) {
200
- const t = [];
192
+ function vt(t) {
193
+ const e = [];
201
194
  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);
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 de(e) {
210
- if (!e.rawResponse)
202
+ function xt(t) {
203
+ if (!t.rawResponse)
211
204
  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
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, {
207
+ status: s || 200,
208
+ headers: l
216
209
  });
217
210
  }
218
- async function pe({
219
- rendered: e,
220
- template: t,
211
+ async function St({
212
+ rendered: t,
213
+ template: e,
221
214
  manifest: n,
222
- root: o,
223
- distClientDir: l,
224
- isProduction: d
215
+ root: s,
216
+ distClientDir: i,
217
+ isProduction: l
225
218
  }) {
226
- const c = de(e);
219
+ const c = xt(t);
227
220
  if (c)
228
221
  return c;
229
- if (e.redirect)
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 $ = 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));
229
+ let a = t.scripts || [], f = t.styles || [];
230
+ const u = t.islands || [];
231
+ let k = t.cacheTags || [];
232
+ const _ = t.maxAge, N = t.sMaxAge, U = t.swr;
233
+ let o = "", p = [], w = "";
234
+ if (l && n) {
235
+ let x = function(r) {
236
+ const m = n[r];
237
+ return m ? (m.css && m.css.forEach((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
- }), { file: p.file }) : { file: null };
243
+ }), { file: m.file }) : { file: null };
251
244
  };
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}`);
245
+ a = a.filter((r) => !r.includes(".global.")), f = f.filter((r) => !r.includes(".global."));
246
+ const g = /* @__PURE__ */ new Set(), T = /* @__PURE__ */ new Set(), M = [];
247
+ for (const r of a) {
248
+ const m = r.replace(/^\//, ""), { file: b } = x(m);
249
+ b && M.push(`/${b}`);
257
250
  }
258
251
  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));
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 (T.length > 0) {
264
- const i = await se(T, o, l);
265
- a = i.filename ? [`/${i.filename}`] : T;
256
+ if (M.length > 0) {
257
+ const r = await pt(M, i);
258
+ a = r.filename ? [`/${r.filename}`] : M;
266
259
  }
267
260
  if (L.length > 0) {
268
- const i = await oe(L, o, l);
269
- i.filename && (g = [`/${i.filename}`]);
261
+ const r = await mt(L, i);
262
+ r.filename && (f = [`/${r.filename}`]);
270
263
  }
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}`);
264
+ const h = n["src/client.global.ts"];
265
+ if (h && (h.css && h.css.length > 0 && h.css.forEach((r) => {
266
+ o += `<link rel="stylesheet" crossorigin href="/${r}">`;
267
+ }), h.file && p.push(`/${h.file}`)), u.length > 0) {
268
+ const r = {};
269
+ for (const m of u) {
270
+ const b = n[m.src];
271
+ b?.file && (r[m.key] = `/${b.file}`);
279
272
  }
280
- Object.keys(i).length > 0 && (s = `<script>window.__L5E_ISLANDS__=${B(i)}<\/script>`);
273
+ Object.keys(r).length > 0 && (w = `<script>window.__L5E_ISLANDS__=${J(r)}<\/script>`);
281
274
  }
282
- g.length > 0 && (r += g.map((i) => `<link rel="stylesheet" crossorigin href="${i}">`).join(""));
275
+ f.length > 0 && (o += f.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
283
276
  }
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>`;
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 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({
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
- }), 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, {
300
- status: e.statusCode || 200,
301
- headers: E
291
+ }), R = ["public"];
292
+ return _ !== void 0 && R.push(`max-age=${_}`), N !== void 0 && R.push(`s-maxage=${N}`), U !== void 0 && R.push(`stale-while-revalidate=${U}`), R.length > 1 && l && C.set("Cache-Control", R.join(", ")), process.env.NODE_ENV === "production" && (k = Ct(k)), C.set("Cache-Tag", ["global", ...k].join(",")), new globalThis.Response($, {
293
+ status: t.statusCode || 200,
294
+ headers: C
302
295
  });
303
296
  }
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();
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));
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");
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(
304
+ const f = d.join(e, "./dist/client");
305
+ if (s) {
306
+ const o = (await import("compression")).default, p = (await import("sirv")).default;
307
+ c.use(o()), c.use(n, p(f, { extensions: [] })), c.get(
315
308
  `${n === "/" ? "" : n}/bundle-:hash.:ext`,
316
- async (s, h) => {
309
+ async (w, y) => {
317
310
  try {
318
- const { hash: v, ext: y } = s.params, A = `bundle-${v}.${y}`, x = re(A);
319
- if (!x)
320
- return h.status(404).send("Bundled file not found");
321
- h.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
- }), h.send(x.content);
325
- } catch (v) {
326
- console.error("[server] Error serving bundled file:", v), h.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: r } = await import("vite"), f = u.join(t, "vite.config.js");
332
- a = await r({
333
- root: t,
334
- configFile: f,
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,
@@ -348,155 +341,156 @@ async function me(e = {}) {
348
341
  }
349
342
  }), c.use(a.middlewares);
350
343
  }
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)
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() {
348
+ if (!s)
356
349
  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);
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 R;
354
+ return k;
362
355
  }
363
- async function C() {
364
- if (!o)
356
+ async function U() {
357
+ if (!s)
365
358
  return (await a.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
366
- if (!j) {
367
- const r = u.join(t, "./dist/server/entry-server.js");
368
- j = (await import(H(r).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 c.all("/_l5e/action/:actionKey", async (r, f) => {
365
+ return c.all("/_l5e/action/:actionKey", async (o, p) => {
373
366
  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;
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]();
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 $;
375
+ if (s) {
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/${y}/actions.tsx`);
382
+ $ = await a.ssrLoadModule(`/src/${v}/actions.tsx`);
390
383
  } catch {
391
- x = await a.ssrLoadModule(`/src/${y}/actions.ts`);
384
+ $ = await a.ssrLoadModule(`/src/${v}/actions.ts`);
392
385
  }
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");
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(
404
+ async () => {
405
+ const rt = await C.handler(O);
406
+ return M(rt);
407
+ },
408
+ O,
409
+ v
410
+ );
411
+ return new Response(st, { headers: { "Content-Type": "text/html" } });
412
+ });
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");
422
416
  }
423
- }), c.use(async (r, f) => {
417
+ }), c.use(async (o, p) => {
424
418
  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(
432
- u.join(t, "./dist/client/.vite/manifest.json"),
419
+ const w = o.originalUrl.replace(n, "");
420
+ let y, S, v, E;
421
+ if (s) {
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"),
433
427
  "utf-8"
434
428
  );
435
- A = JSON.parse(p);
429
+ E = JSON.parse(m);
436
430
  } 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(
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(
438
432
  "</head>",
439
433
  '<script type="module" src="/@vite/client"><\/script></head>'
440
434
  ));
441
- const m = await a.ssrLoadModule(
435
+ const h = await a.ssrLoadModule(
442
436
  "@withl5e/l5e/entry-server"
443
437
  );
444
- v = m.render, y = m.loadMiddleware;
438
+ S = h.render, v = h.loadMiddleware;
445
439
  }
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({
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),
443
+ locals: R,
444
+ clientAddress: V.getClientIp(o)
445
+ }), T = async (h) => {
446
+ const r = D(o, h, n, R), m = nt(r.url, n), b = await S(m, r);
447
+ return St({
454
448
  rendered: b,
455
- template: h,
456
- manifest: A,
457
- root: t,
458
- distClientDir: g,
459
- isProduction: o
449
+ template: y,
450
+ manifest: E,
451
+ root: e,
452
+ distClientDir: f,
453
+ isProduction: s
460
454
  });
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);
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);
464
458
  };
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);
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);
470
464
  }
471
465
  }), { app: c, vite: a };
472
466
  }
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, () => {
478
- 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}`);
479
473
  });
480
474
  }
481
- const ge = 1e3;
482
- function we(e) {
483
- if (e === "global")
475
+ const Rt = 1e3;
476
+ function jt(t) {
477
+ if (t === "global")
484
478
  return "global";
485
- let t = 0;
486
- for (let n = 0; n < e.length; n++) {
487
- const o = e.charCodeAt(n);
488
- t = (t << 5) - t + o, 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;
489
483
  }
490
- return Math.abs(t).toString(36).substring(0, 8);
484
+ return Math.abs(e).toString(36).substring(0, 8);
491
485
  }
492
- function ye(e) {
493
- return (Array.isArray(e) ? e : [...e]).slice(0, ge).map(we);
486
+ function Ct(t) {
487
+ return (Array.isArray(t) ? t : [...t]).slice(0, Rt).map(jt);
494
488
  }
495
489
  export {
496
- ie as applyHtmlLang,
497
- me as createServer,
498
- we as hashTag,
499
- ye as optimizeCacheTags,
500
- Ae as startServer
490
+ gt as applyHtmlLang,
491
+ $t as createServer,
492
+ jt as hashTag,
493
+ Ct as optimizeCacheTags,
494
+ Ht as startServer
501
495
  };
502
496
  //# sourceMappingURL=server.js.map