@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 +362 -369
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/src/core/bundler.ts +201 -205
- package/src/core/server.ts +2 -2
package/dist/server.js
CHANGED
|
@@ -1,337 +1,330 @@
|
|
|
1
|
-
import { existsSync as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { pathToFileURL as
|
|
5
|
-
import
|
|
6
|
-
import { a as
|
|
7
|
-
import { c as
|
|
8
|
-
import { createHash as
|
|
9
|
-
import { createRequire as
|
|
10
|
-
let
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
const
|
|
14
|
-
return await import(
|
|
15
|
-
})()),
|
|
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
|
|
18
|
-
function
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
102
|
-
const
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
107
|
+
} catch (f) {
|
|
108
|
+
console.warn(`[bundler] Failed to read CSS file: ${c}`, f);
|
|
124
109
|
}
|
|
125
|
-
|
|
110
|
+
}
|
|
111
|
+
const s = n.join(`
|
|
126
112
|
|
|
127
|
-
`),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
|
139
|
-
return
|
|
131
|
+
function wt(t) {
|
|
132
|
+
return z.get(t);
|
|
140
133
|
}
|
|
141
|
-
function
|
|
142
|
-
const n =
|
|
143
|
-
return
|
|
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
|
|
146
|
-
return new URL(`${
|
|
138
|
+
function yt(t) {
|
|
139
|
+
return new URL(`${t.protocol}://${t.get("host")}${t.originalUrl}`);
|
|
147
140
|
}
|
|
148
|
-
function
|
|
149
|
-
return `${
|
|
141
|
+
function nt(t, e) {
|
|
142
|
+
return `${t.pathname}${t.search}`.replace(e, "") || "/";
|
|
150
143
|
}
|
|
151
|
-
function
|
|
152
|
-
const
|
|
153
|
-
method:
|
|
154
|
-
headers:
|
|
144
|
+
function Y(t) {
|
|
145
|
+
const e = {
|
|
146
|
+
method: t.method,
|
|
147
|
+
headers: it(t)
|
|
155
148
|
};
|
|
156
|
-
return
|
|
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(
|
|
159
|
-
const
|
|
160
|
-
return
|
|
161
|
-
a[
|
|
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:
|
|
164
|
-
path:
|
|
165
|
-
pathname:
|
|
166
|
-
method:
|
|
156
|
+
url: i,
|
|
157
|
+
path: c,
|
|
158
|
+
pathname: i.pathname,
|
|
159
|
+
method: e.method,
|
|
167
160
|
headers: a,
|
|
168
|
-
cookies:
|
|
169
|
-
query: Object.fromEntries(
|
|
170
|
-
ip:
|
|
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(
|
|
175
|
-
return
|
|
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
|
|
178
|
-
|
|
179
|
-
const s =
|
|
180
|
-
if (n.headers.forEach((
|
|
181
|
-
|
|
182
|
-
}), s.length > 0 &&
|
|
183
|
-
|
|
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
|
|
187
|
-
|
|
179
|
+
const i = Buffer.from(await n.arrayBuffer());
|
|
180
|
+
e.send(i);
|
|
188
181
|
}
|
|
189
|
-
function
|
|
190
|
-
const
|
|
191
|
-
if (typeof
|
|
192
|
-
return
|
|
193
|
-
const n =
|
|
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 =
|
|
197
|
-
return s ?
|
|
189
|
+
const s = t.get("set-cookie");
|
|
190
|
+
return s ? vt(s) : [];
|
|
198
191
|
}
|
|
199
|
-
function
|
|
200
|
-
const
|
|
192
|
+
function vt(t) {
|
|
193
|
+
const e = [];
|
|
201
194
|
let n = 0;
|
|
202
|
-
for (let s = 0; s <
|
|
203
|
-
if (
|
|
204
|
-
const
|
|
205
|
-
/^\s*[^=;,]+=/.test(
|
|
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
|
|
200
|
+
return e.push(t.slice(n).trim()), e.filter(Boolean);
|
|
208
201
|
}
|
|
209
|
-
function
|
|
210
|
-
if (!
|
|
202
|
+
function xt(t) {
|
|
203
|
+
if (!t.rawResponse)
|
|
211
204
|
return null;
|
|
212
|
-
const { body:
|
|
213
|
-
return
|
|
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:
|
|
208
|
+
headers: l
|
|
216
209
|
});
|
|
217
210
|
}
|
|
218
|
-
async function
|
|
219
|
-
rendered:
|
|
220
|
-
template:
|
|
211
|
+
async function St({
|
|
212
|
+
rendered: t,
|
|
213
|
+
template: e,
|
|
221
214
|
manifest: n,
|
|
222
215
|
root: s,
|
|
223
|
-
distClientDir:
|
|
224
|
-
isProduction:
|
|
216
|
+
distClientDir: i,
|
|
217
|
+
isProduction: l
|
|
225
218
|
}) {
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
228
|
-
return
|
|
229
|
-
if (
|
|
219
|
+
const c = xt(t);
|
|
220
|
+
if (c)
|
|
221
|
+
return c;
|
|
222
|
+
if (t.redirect)
|
|
230
223
|
return new globalThis.Response(null, {
|
|
231
|
-
status:
|
|
224
|
+
status: t.redirect.statusCode,
|
|
232
225
|
headers: {
|
|
233
|
-
Location:
|
|
226
|
+
Location: t.redirect.url
|
|
234
227
|
}
|
|
235
228
|
});
|
|
236
|
-
let a =
|
|
237
|
-
const
|
|
238
|
-
let
|
|
239
|
-
const
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
242
|
-
let
|
|
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((
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
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.")),
|
|
253
|
-
const
|
|
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:
|
|
256
|
-
|
|
248
|
+
const m = r.replace(/^\//, ""), { file: b } = x(m);
|
|
249
|
+
b && M.push(`/${b}`);
|
|
257
250
|
}
|
|
258
|
-
const
|
|
259
|
-
for (const r of
|
|
260
|
-
const m = r.replace(/^\//, ""), { file:
|
|
261
|
-
|
|
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 (
|
|
264
|
-
const r = await
|
|
265
|
-
a = r.filename ? [`/${r.filename}`] :
|
|
256
|
+
if (M.length > 0) {
|
|
257
|
+
const r = await pt(M, i);
|
|
258
|
+
a = r.filename ? [`/${r.filename}`] : M;
|
|
266
259
|
}
|
|
267
|
-
if (
|
|
268
|
-
const r = await
|
|
269
|
-
r.filename && (
|
|
260
|
+
if (L.length > 0) {
|
|
261
|
+
const r = await mt(L, i);
|
|
262
|
+
r.filename && (f = [`/${r.filename}`]);
|
|
270
263
|
}
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
}),
|
|
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
|
|
277
|
-
const
|
|
278
|
-
|
|
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 && (
|
|
273
|
+
Object.keys(r).length > 0 && (w = `<script>window.__L5E_ISLANDS__=${J(r)}<\/script>`);
|
|
281
274
|
}
|
|
282
|
-
|
|
275
|
+
f.length > 0 && (o += f.map((r) => `<link rel="stylesheet" crossorigin href="${r}">`).join(""));
|
|
283
276
|
}
|
|
284
|
-
let
|
|
285
|
-
|
|
286
|
-
let
|
|
287
|
-
if (!
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
const
|
|
291
|
-
for (const T of
|
|
292
|
-
|
|
293
|
-
|
|
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
|
|
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
|
|
300
|
-
status:
|
|
301
|
-
headers:
|
|
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
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
const
|
|
308
|
-
|
|
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
|
|
304
|
+
const f = d.join(e, "./dist/client");
|
|
312
305
|
if (s) {
|
|
313
|
-
const
|
|
314
|
-
|
|
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 (
|
|
309
|
+
async (w, y) => {
|
|
317
310
|
try {
|
|
318
|
-
const { hash:
|
|
319
|
-
if (
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
"Content-Type":
|
|
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
|
-
}),
|
|
325
|
-
} catch (
|
|
326
|
-
console.error("[server] Error serving bundled file:",
|
|
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:
|
|
332
|
-
a = await
|
|
333
|
-
root:
|
|
334
|
-
configFile:
|
|
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
|
-
}),
|
|
342
|
+
}), c.use(a.middlewares);
|
|
350
343
|
}
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
async function
|
|
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 (!
|
|
358
|
-
const
|
|
359
|
-
|
|
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
|
|
354
|
+
return k;
|
|
362
355
|
}
|
|
363
|
-
async function
|
|
356
|
+
async function U() {
|
|
364
357
|
if (!s)
|
|
365
358
|
return (await a.ssrLoadModule("virtual:l5e-actions")).viewActions || {};
|
|
366
|
-
if (!
|
|
367
|
-
const
|
|
368
|
-
|
|
359
|
+
if (!_) {
|
|
360
|
+
const o = d.join(e, "./dist/server/entry-server.js");
|
|
361
|
+
_ = (await import(I(o).href)).viewActions || {};
|
|
369
362
|
}
|
|
370
|
-
return
|
|
363
|
+
return _;
|
|
371
364
|
}
|
|
372
|
-
return
|
|
365
|
+
return c.all("/_l5e/action/:actionKey", async (o, p) => {
|
|
373
366
|
try {
|
|
374
|
-
const { actionKey:
|
|
375
|
-
if (!
|
|
376
|
-
return
|
|
377
|
-
const
|
|
378
|
-
if (!
|
|
379
|
-
return
|
|
380
|
-
const { modulePath:
|
|
381
|
-
let
|
|
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
|
|
384
|
-
if (!
|
|
385
|
-
return
|
|
386
|
-
|
|
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
|
-
|
|
382
|
+
$ = await a.ssrLoadModule(`/src/${v}/actions.tsx`);
|
|
390
383
|
} catch {
|
|
391
|
-
|
|
384
|
+
$ = await a.ssrLoadModule(`/src/${v}/actions.ts`);
|
|
392
385
|
}
|
|
393
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
394
|
-
return
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
397
|
-
return
|
|
398
|
-
const R = (
|
|
399
|
-
if (
|
|
400
|
-
return
|
|
401
|
-
const
|
|
402
|
-
request:
|
|
403
|
-
locals:
|
|
404
|
-
clientAddress:
|
|
405
|
-
}), m = await
|
|
406
|
-
const
|
|
407
|
-
...D(
|
|
408
|
-
path:
|
|
409
|
-
body:
|
|
410
|
-
},
|
|
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
|
|
413
|
-
return
|
|
405
|
+
const rt = await C.handler(O);
|
|
406
|
+
return M(rt);
|
|
414
407
|
},
|
|
415
408
|
O,
|
|
416
|
-
|
|
409
|
+
v
|
|
417
410
|
);
|
|
418
|
-
return new Response(
|
|
411
|
+
return new Response(st, { headers: { "Content-Type": "text/html" } });
|
|
419
412
|
});
|
|
420
|
-
await
|
|
421
|
-
} catch (
|
|
422
|
-
a?.ssrFixStacktrace?.(
|
|
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
|
-
}),
|
|
417
|
+
}), c.use(async (o, p) => {
|
|
425
418
|
try {
|
|
426
|
-
const
|
|
427
|
-
let
|
|
419
|
+
const w = o.originalUrl.replace(n, "");
|
|
420
|
+
let y, S, v, E;
|
|
428
421
|
if (s) {
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
const m = await
|
|
433
|
-
|
|
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
|
-
|
|
429
|
+
E = JSON.parse(m);
|
|
437
430
|
} else {
|
|
438
|
-
|
|
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
|
|
435
|
+
const h = await a.ssrLoadModule(
|
|
443
436
|
"@withl5e/l5e/entry-server"
|
|
444
437
|
);
|
|
445
|
-
|
|
438
|
+
S = h.render, v = h.loadMiddleware;
|
|
446
439
|
}
|
|
447
|
-
const
|
|
448
|
-
request:
|
|
449
|
-
requestInfo: D(
|
|
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:
|
|
452
|
-
}), T = async (
|
|
453
|
-
const r = D(
|
|
454
|
-
return
|
|
455
|
-
rendered:
|
|
456
|
-
template:
|
|
457
|
-
manifest:
|
|
458
|
-
root:
|
|
459
|
-
distClientDir:
|
|
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
|
-
},
|
|
463
|
-
const r = X(
|
|
464
|
-
return
|
|
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
|
-
|
|
467
|
-
const
|
|
468
|
-
await
|
|
469
|
-
} catch (
|
|
470
|
-
a?.ssrFixStacktrace?.(
|
|
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:
|
|
465
|
+
}), { app: c, vite: a };
|
|
473
466
|
}
|
|
474
|
-
async function
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
const { app:
|
|
478
|
-
|
|
479
|
-
console.log(`Server started at http://localhost:${
|
|
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
|
|
483
|
-
function
|
|
484
|
-
if (
|
|
475
|
+
const Rt = 1e3;
|
|
476
|
+
function jt(t) {
|
|
477
|
+
if (t === "global")
|
|
485
478
|
return "global";
|
|
486
|
-
let
|
|
487
|
-
for (let n = 0; n <
|
|
488
|
-
const s =
|
|
489
|
-
|
|
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(
|
|
484
|
+
return Math.abs(e).toString(36).substring(0, 8);
|
|
492
485
|
}
|
|
493
|
-
function
|
|
494
|
-
return (Array.isArray(
|
|
486
|
+
function Ct(t) {
|
|
487
|
+
return (Array.isArray(t) ? t : [...t]).slice(0, Rt).map(jt);
|
|
495
488
|
}
|
|
496
489
|
export {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|