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