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