@pyreon/server 0.1.0
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/LICENSE +21 -0
- package/README.md +91 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +294 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +311 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index2.d.ts +190 -0
- package/lib/types/index2.d.ts.map +1 -0
- package/package.json +53 -0
- package/src/client.ts +239 -0
- package/src/handler.ts +187 -0
- package/src/html.ts +58 -0
- package/src/index.ts +69 -0
- package/src/island.ts +137 -0
- package/src/middleware.ts +39 -0
- package/src/ssg.ts +143 -0
- package/src/tests/client.test.ts +577 -0
- package/src/tests/server.test.ts +635 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { h } from "@pyreon/core";
|
|
2
|
+
import { renderWithHead } from "@pyreon/head";
|
|
3
|
+
import { RouterProvider, createRouter, prefetchLoaderData, serializeLoaderData } from "@pyreon/router";
|
|
4
|
+
import { renderToStream, runWithRequestContext } from "@pyreon/runtime-server";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/html.ts
|
|
9
|
+
/**
|
|
10
|
+
* HTML template processing for SSR/SSG.
|
|
11
|
+
*
|
|
12
|
+
* Templates use comment placeholders:
|
|
13
|
+
* <!--pyreon-head--> — replaced with <head> tags (title, meta, link, etc.)
|
|
14
|
+
* <!--pyreon-app--> — replaced with rendered application HTML
|
|
15
|
+
* <!--pyreon-scripts--> — replaced with client entry script + inline loader data
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_TEMPLATE = `<!DOCTYPE html>
|
|
18
|
+
<html lang="en">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="UTF-8">
|
|
21
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
22
|
+
<!--pyreon-head-->
|
|
23
|
+
</head>
|
|
24
|
+
<body>
|
|
25
|
+
<div id="app"><!--pyreon-app--></div>
|
|
26
|
+
<!--pyreon-scripts-->
|
|
27
|
+
</body>
|
|
28
|
+
</html>`;
|
|
29
|
+
function processTemplate(template, data) {
|
|
30
|
+
return template.replace("<!--pyreon-head-->", data.head).replace("<!--pyreon-app-->", data.app).replace("<!--pyreon-scripts-->", data.scripts);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build the script tags for client hydration.
|
|
34
|
+
*
|
|
35
|
+
* Emits:
|
|
36
|
+
* 1. Inline script with serialized loader data (if any)
|
|
37
|
+
* 2. Module script tag pointing to the client entry
|
|
38
|
+
*/
|
|
39
|
+
function buildScripts(clientEntry, loaderData) {
|
|
40
|
+
const parts = [];
|
|
41
|
+
if (loaderData && Object.keys(loaderData).length > 0) {
|
|
42
|
+
const json = JSON.stringify(loaderData).replace(/<\//g, "<\\/");
|
|
43
|
+
parts.push(`<script>window.__PYREON_LOADER_DATA__=${json}<\/script>`);
|
|
44
|
+
}
|
|
45
|
+
parts.push(`<script type="module" src="${clientEntry}"><\/script>`);
|
|
46
|
+
return parts.join("\n ");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/handler.ts
|
|
51
|
+
function createHandler(options) {
|
|
52
|
+
const { App, routes, template = DEFAULT_TEMPLATE, clientEntry = "/src/entry-client.ts", middleware = [], mode = "string" } = options;
|
|
53
|
+
return async function handler(req) {
|
|
54
|
+
const url = new URL(req.url);
|
|
55
|
+
const path = url.pathname + url.search;
|
|
56
|
+
const ctx = {
|
|
57
|
+
req,
|
|
58
|
+
url,
|
|
59
|
+
path,
|
|
60
|
+
headers: new Headers({ "Content-Type": "text/html; charset=utf-8" }),
|
|
61
|
+
locals: {}
|
|
62
|
+
};
|
|
63
|
+
for (const mw of middleware) {
|
|
64
|
+
const result = await mw(ctx);
|
|
65
|
+
if (result instanceof Response) return result;
|
|
66
|
+
}
|
|
67
|
+
const router = createRouter({
|
|
68
|
+
routes,
|
|
69
|
+
mode: "history",
|
|
70
|
+
url: path
|
|
71
|
+
});
|
|
72
|
+
return runWithRequestContext(async () => {
|
|
73
|
+
try {
|
|
74
|
+
await prefetchLoaderData(router, path);
|
|
75
|
+
const app = h(RouterProvider, { router }, h(App, null));
|
|
76
|
+
if (mode === "stream") return renderStreamResponse(app, router, template, clientEntry, ctx.headers);
|
|
77
|
+
const { html: appHtml, head } = await renderWithHead(app);
|
|
78
|
+
const fullHtml = processTemplate(template, {
|
|
79
|
+
head,
|
|
80
|
+
app: appHtml,
|
|
81
|
+
scripts: buildScripts(clientEntry, serializeLoaderData(router))
|
|
82
|
+
});
|
|
83
|
+
return new Response(fullHtml, {
|
|
84
|
+
status: 200,
|
|
85
|
+
headers: ctx.headers
|
|
86
|
+
});
|
|
87
|
+
} catch (_err) {
|
|
88
|
+
return new Response("Internal Server Error", {
|
|
89
|
+
status: 500,
|
|
90
|
+
headers: { "Content-Type": "text/plain" }
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Streaming mode: shell is emitted immediately, app content streams progressively.
|
|
98
|
+
*
|
|
99
|
+
* Head tags from the initial synchronous render are included in the shell.
|
|
100
|
+
* Suspense boundaries resolve out-of-order via inline <template> + swap scripts.
|
|
101
|
+
*/
|
|
102
|
+
async function renderStreamResponse(app, router, template, clientEntry, extraHeaders) {
|
|
103
|
+
const scripts = buildScripts(clientEntry, serializeLoaderData(router));
|
|
104
|
+
const [beforeApp, afterApp] = template.split("<!--pyreon-app-->");
|
|
105
|
+
if (!beforeApp || afterApp === void 0) throw new Error("[pyreon/server] Template must contain <!--pyreon-app--> placeholder");
|
|
106
|
+
const shellHead = beforeApp.replace("<!--pyreon-head-->", "");
|
|
107
|
+
const shellTail = afterApp.replace("<!--pyreon-scripts-->", scripts);
|
|
108
|
+
const reader = renderToStream(app).getReader();
|
|
109
|
+
const stream = new ReadableStream({ async start(controller) {
|
|
110
|
+
const encoder = new TextEncoder();
|
|
111
|
+
const push = (s) => controller.enqueue(encoder.encode(s));
|
|
112
|
+
try {
|
|
113
|
+
push(shellHead);
|
|
114
|
+
let done = false;
|
|
115
|
+
while (!done) {
|
|
116
|
+
const result = await reader.read();
|
|
117
|
+
done = result.done;
|
|
118
|
+
if (result.value) push(result.value);
|
|
119
|
+
}
|
|
120
|
+
push(shellTail);
|
|
121
|
+
} catch (_err) {
|
|
122
|
+
push(`<script>console.error("[pyreon/server] Stream render failed")<\/script>`);
|
|
123
|
+
push(shellTail);
|
|
124
|
+
} finally {
|
|
125
|
+
controller.close();
|
|
126
|
+
}
|
|
127
|
+
} });
|
|
128
|
+
return new Response(stream, {
|
|
129
|
+
status: 200,
|
|
130
|
+
headers: extraHeaders
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/island.ts
|
|
136
|
+
/**
|
|
137
|
+
* Create an island component.
|
|
138
|
+
*
|
|
139
|
+
* Returns an async ComponentFn that:
|
|
140
|
+
* 1. Resolves the dynamic import
|
|
141
|
+
* 2. Renders the component to VNodes
|
|
142
|
+
* 3. Wraps the output in `<pyreon-island>` with serialized props + hydration strategy
|
|
143
|
+
*/
|
|
144
|
+
function island(loader, options) {
|
|
145
|
+
const { name, hydrate = "load" } = options;
|
|
146
|
+
const wrapper = async function IslandWrapper(props) {
|
|
147
|
+
const mod = await loader();
|
|
148
|
+
const Comp = typeof mod === "function" ? mod : mod.default;
|
|
149
|
+
const serializedProps = serializeIslandProps(props);
|
|
150
|
+
return h("pyreon-island", {
|
|
151
|
+
"data-component": name,
|
|
152
|
+
"data-props": serializedProps,
|
|
153
|
+
"data-hydrate": hydrate
|
|
154
|
+
}, h(Comp, props));
|
|
155
|
+
};
|
|
156
|
+
Object.defineProperties(wrapper, {
|
|
157
|
+
__island: {
|
|
158
|
+
value: true,
|
|
159
|
+
enumerable: true
|
|
160
|
+
},
|
|
161
|
+
name: {
|
|
162
|
+
value: name,
|
|
163
|
+
enumerable: true,
|
|
164
|
+
writable: false,
|
|
165
|
+
configurable: true
|
|
166
|
+
},
|
|
167
|
+
hydrate: {
|
|
168
|
+
value: hydrate,
|
|
169
|
+
enumerable: true
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return wrapper;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Serialize component props to a JSON string for embedding in HTML attributes.
|
|
176
|
+
* Strips non-serializable values (functions, symbols, children).
|
|
177
|
+
*/
|
|
178
|
+
function serializeIslandProps(props) {
|
|
179
|
+
const clean = {};
|
|
180
|
+
for (const [key, value] of Object.entries(props)) {
|
|
181
|
+
if (key === "children") continue;
|
|
182
|
+
if (typeof value === "function") continue;
|
|
183
|
+
if (typeof value === "symbol") continue;
|
|
184
|
+
if (value === void 0) continue;
|
|
185
|
+
clean[key] = value;
|
|
186
|
+
}
|
|
187
|
+
return JSON.stringify(clean);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/ssg.ts
|
|
192
|
+
/**
|
|
193
|
+
* Static Site Generation — pre-render routes to HTML files at build time.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* // ssg.ts (run with: bun run ssg.ts)
|
|
197
|
+
* import { createHandler } from "@pyreon/server"
|
|
198
|
+
* import { prerender } from "@pyreon/server"
|
|
199
|
+
* import { App } from "./src/App"
|
|
200
|
+
* import { routes } from "./src/routes"
|
|
201
|
+
*
|
|
202
|
+
* const handler = createHandler({ App, routes })
|
|
203
|
+
*
|
|
204
|
+
* await prerender({
|
|
205
|
+
* handler,
|
|
206
|
+
* paths: ["/", "/about", "/blog", "/blog/hello-world"],
|
|
207
|
+
* outDir: "dist",
|
|
208
|
+
* })
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* // Dynamic paths from a CMS or filesystem
|
|
212
|
+
* await prerender({
|
|
213
|
+
* handler,
|
|
214
|
+
* paths: async () => {
|
|
215
|
+
* const posts = await fetchAllPosts()
|
|
216
|
+
* return ["/", "/about", ...posts.map(p => `/blog/${p.slug}`)]
|
|
217
|
+
* },
|
|
218
|
+
* outDir: "dist",
|
|
219
|
+
* })
|
|
220
|
+
*/
|
|
221
|
+
/**
|
|
222
|
+
* Pre-render a list of routes to static HTML files.
|
|
223
|
+
*
|
|
224
|
+
* For each path:
|
|
225
|
+
* 1. Constructs a Request for the path
|
|
226
|
+
* 2. Calls the SSR handler to render to HTML
|
|
227
|
+
* 3. Writes the HTML to `outDir/<path>/index.html`
|
|
228
|
+
*
|
|
229
|
+
* The root path "/" becomes `outDir/index.html`.
|
|
230
|
+
* Paths like "/about" become `outDir/about/index.html`.
|
|
231
|
+
*/
|
|
232
|
+
async function prerender(options) {
|
|
233
|
+
const { handler, outDir, origin = "http://localhost", onPage } = options;
|
|
234
|
+
const start = Date.now();
|
|
235
|
+
const paths = typeof options.paths === "function" ? await options.paths() : options.paths;
|
|
236
|
+
let pages = 0;
|
|
237
|
+
const errors = [];
|
|
238
|
+
async function renderPage(path) {
|
|
239
|
+
const url = new URL(path, origin);
|
|
240
|
+
const req = new Request(url.href);
|
|
241
|
+
const res = await Promise.race([handler(req), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`Prerender timeout for "${path}" (30s)`)), 3e4))]);
|
|
242
|
+
if (!res.ok) {
|
|
243
|
+
errors.push({
|
|
244
|
+
path,
|
|
245
|
+
error: /* @__PURE__ */ new Error(`HTTP ${res.status}`)
|
|
246
|
+
});
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const html = await res.text();
|
|
250
|
+
if (onPage) {
|
|
251
|
+
if (await onPage(path, html) === false) return;
|
|
252
|
+
}
|
|
253
|
+
const filePath = resolveOutputPath(outDir, path);
|
|
254
|
+
const resolvedOut = resolve(outDir);
|
|
255
|
+
if (!resolve(filePath).startsWith(resolvedOut)) {
|
|
256
|
+
errors.push({
|
|
257
|
+
path,
|
|
258
|
+
error: /* @__PURE__ */ new Error(`Path traversal detected: "${path}"`)
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
263
|
+
await writeFile(filePath, html, "utf-8");
|
|
264
|
+
pages++;
|
|
265
|
+
}
|
|
266
|
+
const BATCH_SIZE = 10;
|
|
267
|
+
for (let i = 0; i < paths.length; i += BATCH_SIZE) {
|
|
268
|
+
const batch = paths.slice(i, i + BATCH_SIZE);
|
|
269
|
+
await Promise.all(batch.map(async (path) => {
|
|
270
|
+
try {
|
|
271
|
+
await renderPage(path);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
errors.push({
|
|
274
|
+
path,
|
|
275
|
+
error
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
pages,
|
|
282
|
+
errors,
|
|
283
|
+
elapsed: Date.now() - start
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function resolveOutputPath(outDir, path) {
|
|
287
|
+
if (path === "/") return join(outDir, "index.html");
|
|
288
|
+
if (path.endsWith(".html")) return join(outDir, path);
|
|
289
|
+
return join(outDir, path, "index.html");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
//#endregion
|
|
293
|
+
export { DEFAULT_TEMPLATE, buildScripts, createHandler, island, prerender, processTemplate };
|
|
294
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/html.ts","../src/handler.ts","../src/island.ts","../src/ssg.ts"],"sourcesContent":["/**\n * HTML template processing for SSR/SSG.\n *\n * Templates use comment placeholders:\n * <!--pyreon-head--> — replaced with <head> tags (title, meta, link, etc.)\n * <!--pyreon-app--> — replaced with rendered application HTML\n * <!--pyreon-scripts--> — replaced with client entry script + inline loader data\n */\n\nexport const DEFAULT_TEMPLATE = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <!--pyreon-head-->\n</head>\n<body>\n <div id=\"app\"><!--pyreon-app--></div>\n <!--pyreon-scripts-->\n</body>\n</html>`\n\nexport interface TemplateData {\n head: string\n app: string\n scripts: string\n}\n\nexport function processTemplate(template: string, data: TemplateData): string {\n return template\n .replace(\"<!--pyreon-head-->\", data.head)\n .replace(\"<!--pyreon-app-->\", data.app)\n .replace(\"<!--pyreon-scripts-->\", data.scripts)\n}\n\n/**\n * Build the script tags for client hydration.\n *\n * Emits:\n * 1. Inline script with serialized loader data (if any)\n * 2. Module script tag pointing to the client entry\n */\nexport function buildScripts(\n clientEntry: string,\n loaderData: Record<string, unknown> | null,\n): string {\n const parts: string[] = []\n\n if (loaderData && Object.keys(loaderData).length > 0) {\n // Escape </script> inside JSON to prevent premature tag close\n const json = JSON.stringify(loaderData).replace(/<\\//g, \"<\\\\/\")\n parts.push(`<script>window.__PYREON_LOADER_DATA__=${json}</script>`)\n }\n\n parts.push(`<script type=\"module\" src=\"${clientEntry}\"></script>`)\n\n return parts.join(\"\\n \")\n}\n","/**\n * SSR request handler.\n *\n * Creates a Web-standard `(Request) => Promise<Response>` handler that:\n * 1. Runs middleware (auth, redirects, headers, etc.)\n * 2. Creates a per-request router with the matched URL\n * 3. Prefetches loader data for matched routes\n * 4. Renders the app to HTML with head tag collection\n * 5. Injects everything into an HTML template\n * 6. Returns a Response\n *\n * Compatible with Bun.serve, Deno.serve, Cloudflare Workers,\n * Express (via adapter), and any Web-standard server.\n *\n * @example\n * import { createHandler } from \"@pyreon/server\"\n *\n * const handler = createHandler({\n * App,\n * routes,\n * template: await Bun.file(\"index.html\").text(),\n * })\n *\n * Bun.serve({ fetch: handler })\n */\n\nimport type { ComponentFn } from \"@pyreon/core\"\nimport { h } from \"@pyreon/core\"\nimport { renderWithHead } from \"@pyreon/head\"\nimport {\n createRouter,\n prefetchLoaderData,\n type RouteRecord,\n RouterProvider,\n serializeLoaderData,\n} from \"@pyreon/router\"\nimport { renderToStream, runWithRequestContext } from \"@pyreon/runtime-server\"\nimport { buildScripts, DEFAULT_TEMPLATE, processTemplate } from \"./html\"\nimport type { Middleware, MiddlewareContext } from \"./middleware\"\n\nexport interface HandlerOptions {\n /** Root application component */\n App: ComponentFn\n /** Route definitions */\n routes: RouteRecord[]\n /**\n * HTML template with placeholders:\n * <!--pyreon-head--> — head tags (title, meta, link, etc.)\n * <!--pyreon-app--> — rendered app HTML\n * <!--pyreon-scripts--> — client entry + loader data\n *\n * Defaults to a minimal HTML5 template.\n */\n template?: string\n /** Path to the client entry module (default: \"/src/entry-client.ts\") */\n clientEntry?: string\n /** Middleware chain — runs before rendering */\n middleware?: Middleware[]\n /**\n * Rendering mode:\n * \"string\" (default) — full renderToString, complete HTML in one response\n * \"stream\" — progressive streaming via renderToStream (Suspense out-of-order)\n */\n mode?: \"string\" | \"stream\"\n}\n\nexport function createHandler(options: HandlerOptions): (req: Request) => Promise<Response> {\n const {\n App,\n routes,\n template = DEFAULT_TEMPLATE,\n clientEntry = \"/src/entry-client.ts\",\n middleware = [],\n mode = \"string\",\n } = options\n\n return async function handler(req: Request): Promise<Response> {\n const url = new URL(req.url)\n const path = url.pathname + url.search\n\n // ── Middleware pipeline ────────────────────────────────────────────────────\n const ctx: MiddlewareContext = {\n req,\n url,\n path,\n headers: new Headers({ \"Content-Type\": \"text/html; charset=utf-8\" }),\n locals: {},\n }\n\n for (const mw of middleware) {\n const result = await mw(ctx)\n if (result instanceof Response) return result\n }\n\n // ── Per-request router ────────────────────────────────────────────────────\n const router = createRouter({ routes, mode: \"history\", url: path })\n\n return runWithRequestContext(async () => {\n try {\n // Pre-run loaders so data is available during render\n await prefetchLoaderData(router as never, path)\n\n // Build the VNode tree\n const app = h(RouterProvider, { router }, h(App, null))\n\n if (mode === \"stream\") {\n return renderStreamResponse(app, router, template, clientEntry, ctx.headers)\n }\n\n // ── String mode (default) ─────────────────────────────────────────────\n const { html: appHtml, head } = await renderWithHead(app)\n const loaderData = serializeLoaderData(router as never)\n const scripts = buildScripts(clientEntry, loaderData)\n const fullHtml = processTemplate(template, { head, app: appHtml, scripts })\n\n return new Response(fullHtml, { status: 200, headers: ctx.headers })\n } catch (_err) {\n return new Response(\"Internal Server Error\", {\n status: 500,\n headers: { \"Content-Type\": \"text/plain\" },\n })\n }\n })\n }\n}\n\n/**\n * Streaming mode: shell is emitted immediately, app content streams progressively.\n *\n * Head tags from the initial synchronous render are included in the shell.\n * Suspense boundaries resolve out-of-order via inline <template> + swap scripts.\n */\nasync function renderStreamResponse(\n app: ReturnType<typeof h>,\n router: ReturnType<typeof createRouter>,\n template: string,\n clientEntry: string,\n extraHeaders: Headers,\n): Promise<Response> {\n const loaderData = serializeLoaderData(router as never)\n const scripts = buildScripts(clientEntry, loaderData)\n\n // Split template around <!--pyreon-app-->\n const [beforeApp, afterApp] = template.split(\"<!--pyreon-app-->\")\n if (!beforeApp || afterApp === undefined) {\n throw new Error(\"[pyreon/server] Template must contain <!--pyreon-app--> placeholder\")\n }\n\n // Replace other placeholders in shell parts\n const shellHead = beforeApp.replace(\"<!--pyreon-head-->\", \"\")\n const shellTail = afterApp.replace(\"<!--pyreon-scripts-->\", scripts)\n\n const appStream = renderToStream(app)\n const reader = appStream.getReader()\n\n const stream = new ReadableStream<Uint8Array>({\n async start(controller) {\n const encoder = new TextEncoder()\n const push = (s: string) => controller.enqueue(encoder.encode(s))\n\n try {\n push(shellHead)\n\n // Stream app content\n let done = false\n while (!done) {\n const result = await reader.read()\n done = result.done\n if (result.value) push(result.value)\n }\n\n push(shellTail)\n } catch (_err) {\n // Emit an inline error indicator — status code is already sent (200)\n push(`<script>console.error(\"[pyreon/server] Stream render failed\")</script>`)\n push(shellTail)\n } finally {\n controller.close()\n }\n },\n })\n\n return new Response(stream, {\n status: 200,\n headers: extraHeaders,\n })\n}\n","/**\n * Island architecture — partial hydration for content-heavy sites.\n *\n * Islands are interactive components embedded in otherwise-static HTML.\n * Only island components ship JavaScript to the client — the rest of the\n * page stays as zero-JS server-rendered HTML.\n *\n * ## Server side\n *\n * `island()` wraps an async component import and returns a ComponentFn.\n * During SSR, it renders the component output inside a `<pyreon-island>` element\n * with serialized props, so the client knows what to hydrate.\n *\n * ```tsx\n * import { island } from \"@pyreon/server\"\n *\n * const Counter = island(() => import(\"./Counter\"), { name: \"Counter\" })\n * const Search = island(() => import(\"./Search\"), { name: \"Search\" })\n *\n * function Page() {\n * return <div>\n * <h1>Static heading (no JS)</h1>\n * <Counter initial={5} /> // hydrated on client\n * <p>Static paragraph</p>\n * <Search /> // hydrated on client\n * </div>\n * }\n * ```\n *\n * ## Client side\n *\n * Use `hydrateIslands()` from `@pyreon/server/client` to hydrate all islands\n * on the page. Only the island components' JavaScript is loaded.\n *\n * ```ts\n * // entry-client.ts (island mode)\n * import { hydrateIslands } from \"@pyreon/server/client\"\n *\n * hydrateIslands({\n * Counter: () => import(\"./Counter\"),\n * Search: () => import(\"./Search\"),\n * })\n * ```\n *\n * ## Hydration strategies\n *\n * Control when an island hydrates via the `hydrate` option:\n * - \"load\" (default) — hydrate immediately on page load\n * - \"idle\" — hydrate when the browser is idle (requestIdleCallback)\n * - \"visible\" — hydrate when the island scrolls into the viewport\n * - \"media(query)\" — hydrate when a media query matches\n * - \"never\" — never hydrate (render-only, no client JS)\n */\n\nimport type { ComponentFn, Props, VNode } from \"@pyreon/core\"\nimport { h } from \"@pyreon/core\"\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\nexport type HydrationStrategy = \"load\" | \"idle\" | \"visible\" | \"never\" | `media(${string})`\n\nexport interface IslandOptions {\n /** Unique name — must match the key in the client-side hydrateIslands() registry */\n name: string\n /** When to hydrate on the client (default: \"load\") */\n hydrate?: HydrationStrategy\n}\n\nexport interface IslandMeta {\n readonly __island: true\n readonly name: string\n readonly hydrate: HydrationStrategy\n}\n\n// ─── Server-side island factory ──────────────────────────────────────────────\n\n/**\n * Create an island component.\n *\n * Returns an async ComponentFn that:\n * 1. Resolves the dynamic import\n * 2. Renders the component to VNodes\n * 3. Wraps the output in `<pyreon-island>` with serialized props + hydration strategy\n */\nexport function island<P extends Props = Props>(\n loader: () => Promise<{ default: ComponentFn<P> } | ComponentFn<P>>,\n options: IslandOptions,\n): ComponentFn<P> & IslandMeta {\n const { name, hydrate = \"load\" } = options\n\n const IslandWrapper = async function IslandWrapper(props: P): Promise<VNode | null> {\n const mod = await loader()\n const Comp = typeof mod === \"function\" ? mod : mod.default\n const serializedProps = serializeIslandProps(props)\n\n return h(\n \"pyreon-island\",\n {\n \"data-component\": name,\n \"data-props\": serializedProps,\n \"data-hydrate\": hydrate,\n },\n h(Comp, props),\n )\n }\n\n // Attach metadata so the Vite plugin can detect islands for code-splitting\n const wrapper = IslandWrapper as unknown as ComponentFn<P> & IslandMeta\n Object.defineProperties(wrapper, {\n __island: { value: true, enumerable: true },\n name: { value: name, enumerable: true, writable: false, configurable: true },\n hydrate: { value: hydrate, enumerable: true },\n })\n\n return wrapper\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\n/**\n * Serialize component props to a JSON string for embedding in HTML attributes.\n * Strips non-serializable values (functions, symbols, children).\n */\nfunction serializeIslandProps(props: Record<string, unknown>): string {\n const clean: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(props)) {\n // Skip non-serializable or internal props\n if (key === \"children\") continue\n if (typeof value === \"function\") continue\n if (typeof value === \"symbol\") continue\n if (value === undefined) continue\n clean[key] = value\n }\n // The SSR renderer's renderProp() already applies escapeHtml() to attribute\n // values, so the JSON is safe to embed in HTML attributes without double-escaping.\n return JSON.stringify(clean)\n}\n","/**\n * Static Site Generation — pre-render routes to HTML files at build time.\n *\n * @example\n * // ssg.ts (run with: bun run ssg.ts)\n * import { createHandler } from \"@pyreon/server\"\n * import { prerender } from \"@pyreon/server\"\n * import { App } from \"./src/App\"\n * import { routes } from \"./src/routes\"\n *\n * const handler = createHandler({ App, routes })\n *\n * await prerender({\n * handler,\n * paths: [\"/\", \"/about\", \"/blog\", \"/blog/hello-world\"],\n * outDir: \"dist\",\n * })\n *\n * @example\n * // Dynamic paths from a CMS or filesystem\n * await prerender({\n * handler,\n * paths: async () => {\n * const posts = await fetchAllPosts()\n * return [\"/\", \"/about\", ...posts.map(p => `/blog/${p.slug}`)]\n * },\n * outDir: \"dist\",\n * })\n */\n\nimport { mkdir, writeFile } from \"node:fs/promises\"\nimport { dirname, join, resolve } from \"node:path\"\n\nexport interface PrerenderOptions {\n /** SSR handler created by createHandler() */\n handler: (req: Request) => Promise<Response>\n /** Routes to pre-render — array of URL paths or async function that returns them */\n paths: string[] | (() => string[] | Promise<string[]>)\n /** Output directory for the generated HTML files */\n outDir: string\n /** Origin for constructing full URLs (default: \"http://localhost\") */\n origin?: string\n /**\n * Called after each page is rendered — use for logging or progress tracking.\n * Return false to skip writing this page.\n */\n // biome-ignore lint/suspicious/noConfusingVoidType: void is intentional\n onPage?: (path: string, html: string) => void | boolean | Promise<void | boolean>\n}\n\nexport interface PrerenderResult {\n /** Number of pages generated */\n pages: number\n /** Paths that failed to render */\n errors: { path: string; error: unknown }[]\n /** Total elapsed time in milliseconds */\n elapsed: number\n}\n\n/**\n * Pre-render a list of routes to static HTML files.\n *\n * For each path:\n * 1. Constructs a Request for the path\n * 2. Calls the SSR handler to render to HTML\n * 3. Writes the HTML to `outDir/<path>/index.html`\n *\n * The root path \"/\" becomes `outDir/index.html`.\n * Paths like \"/about\" become `outDir/about/index.html`.\n */\nexport async function prerender(options: PrerenderOptions): Promise<PrerenderResult> {\n const { handler, outDir, origin = \"http://localhost\", onPage } = options\n\n const start = Date.now()\n\n // Resolve paths (may be async)\n const paths = typeof options.paths === \"function\" ? await options.paths() : options.paths\n\n let pages = 0\n const errors: PrerenderResult[\"errors\"] = []\n\n async function renderPage(path: string): Promise<void> {\n const url = new URL(path, origin)\n const req = new Request(url.href)\n const res = await Promise.race([\n handler(req),\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error(`Prerender timeout for \"${path}\" (30s)`)), 30_000),\n ),\n ])\n\n if (!res.ok) {\n errors.push({ path, error: new Error(`HTTP ${res.status}`) })\n return\n }\n\n const html = await res.text()\n\n if (onPage) {\n const result = await onPage(path, html)\n if (result === false) return\n }\n\n const filePath = resolveOutputPath(outDir, path)\n\n const resolvedOut = resolve(outDir)\n if (!resolve(filePath).startsWith(resolvedOut)) {\n errors.push({ path, error: new Error(`Path traversal detected: \"${path}\"`) })\n return\n }\n\n await mkdir(dirname(filePath), { recursive: true })\n await writeFile(filePath, html, \"utf-8\")\n pages++\n }\n\n // Process paths concurrently (batch of 10 to avoid overwhelming)\n const BATCH_SIZE = 10\n for (let i = 0; i < paths.length; i += BATCH_SIZE) {\n const batch = paths.slice(i, i + BATCH_SIZE)\n await Promise.all(\n batch.map(async (path) => {\n try {\n await renderPage(path)\n } catch (error) {\n errors.push({ path, error })\n }\n }),\n )\n }\n\n return {\n pages,\n errors,\n elapsed: Date.now() - start,\n }\n}\n\nfunction resolveOutputPath(outDir: string, path: string): string {\n if (path === \"/\") return join(outDir, \"index.html\")\n if (path.endsWith(\".html\")) return join(outDir, path)\n return join(outDir, path, \"index.html\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,MAAa,mBAAmB;;;;;;;;;;;;AAmBhC,SAAgB,gBAAgB,UAAkB,MAA4B;AAC5E,QAAO,SACJ,QAAQ,sBAAsB,KAAK,KAAK,CACxC,QAAQ,qBAAqB,KAAK,IAAI,CACtC,QAAQ,yBAAyB,KAAK,QAAQ;;;;;;;;;AAUnD,SAAgB,aACd,aACA,YACQ;CACR,MAAM,QAAkB,EAAE;AAE1B,KAAI,cAAc,OAAO,KAAK,WAAW,CAAC,SAAS,GAAG;EAEpD,MAAM,OAAO,KAAK,UAAU,WAAW,CAAC,QAAQ,QAAQ,OAAO;AAC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AK;EAEhD,MAAM,cAAc,QAAQ,OAAO;AACnC,MAAI,CAAC,QAAQ,SAAS,CAAC,WAAW,YAAY,EAAE;AAC9C,UAAO,KAAK;IAAE;IAAM,uBAAO,IAAI,MAAM,6BAA6B,KAAK,GAAG;IAAE,CAAC;AAC7E;;AAGF,QAAM,MAAM,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,QAAM,UAAU,UAAU,MAAM,QAAQ;AACxC;;CAIF,MAAM,aAAa;AACnB,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,YAAY;EACjD,MAAM,QAAQ,MAAM,MAAM,GAAG,IAAI,WAAW;AAC5C,QAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;AACxB,OAAI;AACF,UAAM,WAAW,KAAK;YACf,OAAO;AACd,WAAO,KAAK;KAAE;KAAM;KAAO,CAAC;;IAE9B,CACH;;AAGH,QAAO;EACL;EACA;EACA,SAAS,KAAK,KAAK,GAAG;EACvB;;AAGH,SAAS,kBAAkB,QAAgB,MAAsB;AAC/D,KAAI,SAAS,IAAK,QAAO,KAAK,QAAQ,aAAa;AACnD,KAAI,KAAK,SAAS,QAAQ,CAAE,QAAO,KAAK,QAAQ,KAAK;AACrD,QAAO,KAAK,QAAQ,MAAM,aAAa"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { h } from "@pyreon/core";
|
|
2
|
+
import { renderWithHead } from "@pyreon/head";
|
|
3
|
+
import { RouterProvider, createRouter, prefetchLoaderData, serializeLoaderData } from "@pyreon/router";
|
|
4
|
+
import { renderToStream, runWithRequestContext } from "@pyreon/runtime-server";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/html.ts
|
|
9
|
+
/**
|
|
10
|
+
* HTML template processing for SSR/SSG.
|
|
11
|
+
*
|
|
12
|
+
* Templates use comment placeholders:
|
|
13
|
+
* <!--pyreon-head--> — replaced with <head> tags (title, meta, link, etc.)
|
|
14
|
+
* <!--pyreon-app--> — replaced with rendered application HTML
|
|
15
|
+
* <!--pyreon-scripts--> — replaced with client entry script + inline loader data
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function processTemplate(template, data) {
|
|
19
|
+
return template.replace("<!--pyreon-head-->", data.head).replace("<!--pyreon-app-->", data.app).replace("<!--pyreon-scripts-->", data.scripts);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build the script tags for client hydration.
|
|
23
|
+
*
|
|
24
|
+
* Emits:
|
|
25
|
+
* 1. Inline script with serialized loader data (if any)
|
|
26
|
+
* 2. Module script tag pointing to the client entry
|
|
27
|
+
*/
|
|
28
|
+
function buildScripts(clientEntry, loaderData) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (loaderData && Object.keys(loaderData).length > 0) {
|
|
31
|
+
const json = JSON.stringify(loaderData).replace(/<\//g, "<\\/");
|
|
32
|
+
parts.push(`<script>window.__PYREON_LOADER_DATA__=${json}<\/script>`);
|
|
33
|
+
}
|
|
34
|
+
parts.push(`<script type="module" src="${clientEntry}"><\/script>`);
|
|
35
|
+
return parts.join("\n ");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/handler.ts
|
|
40
|
+
function createHandler(options) {
|
|
41
|
+
const {
|
|
42
|
+
App,
|
|
43
|
+
routes,
|
|
44
|
+
template = DEFAULT_TEMPLATE,
|
|
45
|
+
clientEntry = "/src/entry-client.ts",
|
|
46
|
+
middleware = [],
|
|
47
|
+
mode = "string"
|
|
48
|
+
} = options;
|
|
49
|
+
return async function handler(req) {
|
|
50
|
+
const url = new URL(req.url);
|
|
51
|
+
const path = url.pathname + url.search;
|
|
52
|
+
const ctx = {
|
|
53
|
+
req,
|
|
54
|
+
url,
|
|
55
|
+
path,
|
|
56
|
+
headers: new Headers({
|
|
57
|
+
"Content-Type": "text/html; charset=utf-8"
|
|
58
|
+
}),
|
|
59
|
+
locals: {}
|
|
60
|
+
};
|
|
61
|
+
for (const mw of middleware) {
|
|
62
|
+
const result = await mw(ctx);
|
|
63
|
+
if (result instanceof Response) return result;
|
|
64
|
+
}
|
|
65
|
+
const router = createRouter({
|
|
66
|
+
routes,
|
|
67
|
+
mode: "history",
|
|
68
|
+
url: path
|
|
69
|
+
});
|
|
70
|
+
return runWithRequestContext(async () => {
|
|
71
|
+
try {
|
|
72
|
+
await prefetchLoaderData(router, path);
|
|
73
|
+
const app = h(RouterProvider, {
|
|
74
|
+
router
|
|
75
|
+
}, h(App, null));
|
|
76
|
+
if (mode === "stream") return renderStreamResponse(app, router, template, clientEntry, ctx.headers);
|
|
77
|
+
const {
|
|
78
|
+
html: appHtml,
|
|
79
|
+
head
|
|
80
|
+
} = await renderWithHead(app);
|
|
81
|
+
const fullHtml = processTemplate(template, {
|
|
82
|
+
head,
|
|
83
|
+
app: appHtml,
|
|
84
|
+
scripts: buildScripts(clientEntry, serializeLoaderData(router))
|
|
85
|
+
});
|
|
86
|
+
return new Response(fullHtml, {
|
|
87
|
+
status: 200,
|
|
88
|
+
headers: ctx.headers
|
|
89
|
+
});
|
|
90
|
+
} catch (_err) {
|
|
91
|
+
return new Response("Internal Server Error", {
|
|
92
|
+
status: 500,
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "text/plain"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Streaming mode: shell is emitted immediately, app content streams progressively.
|
|
103
|
+
*
|
|
104
|
+
* Head tags from the initial synchronous render are included in the shell.
|
|
105
|
+
* Suspense boundaries resolve out-of-order via inline <template> + swap scripts.
|
|
106
|
+
*/
|
|
107
|
+
async function renderStreamResponse(app, router, template, clientEntry, extraHeaders) {
|
|
108
|
+
const scripts = buildScripts(clientEntry, serializeLoaderData(router));
|
|
109
|
+
const [beforeApp, afterApp] = template.split("<!--pyreon-app-->");
|
|
110
|
+
if (!beforeApp || afterApp === void 0) throw new Error("[pyreon/server] Template must contain <!--pyreon-app--> placeholder");
|
|
111
|
+
const shellHead = beforeApp.replace("<!--pyreon-head-->", "");
|
|
112
|
+
const shellTail = afterApp.replace("<!--pyreon-scripts-->", scripts);
|
|
113
|
+
const reader = renderToStream(app).getReader();
|
|
114
|
+
const stream = new ReadableStream({
|
|
115
|
+
async start(controller) {
|
|
116
|
+
const encoder = new TextEncoder();
|
|
117
|
+
const push = s => controller.enqueue(encoder.encode(s));
|
|
118
|
+
try {
|
|
119
|
+
push(shellHead);
|
|
120
|
+
let done = false;
|
|
121
|
+
while (!done) {
|
|
122
|
+
const result = await reader.read();
|
|
123
|
+
done = result.done;
|
|
124
|
+
if (result.value) push(result.value);
|
|
125
|
+
}
|
|
126
|
+
push(shellTail);
|
|
127
|
+
} catch (_err) {
|
|
128
|
+
push(`<script>console.error("[pyreon/server] Stream render failed")<\/script>`);
|
|
129
|
+
push(shellTail);
|
|
130
|
+
} finally {
|
|
131
|
+
controller.close();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return new Response(stream, {
|
|
136
|
+
status: 200,
|
|
137
|
+
headers: extraHeaders
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/island.ts
|
|
143
|
+
/**
|
|
144
|
+
* Create an island component.
|
|
145
|
+
*
|
|
146
|
+
* Returns an async ComponentFn that:
|
|
147
|
+
* 1. Resolves the dynamic import
|
|
148
|
+
* 2. Renders the component to VNodes
|
|
149
|
+
* 3. Wraps the output in `<pyreon-island>` with serialized props + hydration strategy
|
|
150
|
+
*/
|
|
151
|
+
function island(loader, options) {
|
|
152
|
+
const {
|
|
153
|
+
name,
|
|
154
|
+
hydrate = "load"
|
|
155
|
+
} = options;
|
|
156
|
+
const wrapper = async function IslandWrapper(props) {
|
|
157
|
+
const mod = await loader();
|
|
158
|
+
const Comp = typeof mod === "function" ? mod : mod.default;
|
|
159
|
+
const serializedProps = serializeIslandProps(props);
|
|
160
|
+
return h("pyreon-island", {
|
|
161
|
+
"data-component": name,
|
|
162
|
+
"data-props": serializedProps,
|
|
163
|
+
"data-hydrate": hydrate
|
|
164
|
+
}, h(Comp, props));
|
|
165
|
+
};
|
|
166
|
+
Object.defineProperties(wrapper, {
|
|
167
|
+
__island: {
|
|
168
|
+
value: true,
|
|
169
|
+
enumerable: true
|
|
170
|
+
},
|
|
171
|
+
name: {
|
|
172
|
+
value: name,
|
|
173
|
+
enumerable: true,
|
|
174
|
+
writable: false,
|
|
175
|
+
configurable: true
|
|
176
|
+
},
|
|
177
|
+
hydrate: {
|
|
178
|
+
value: hydrate,
|
|
179
|
+
enumerable: true
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return wrapper;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Serialize component props to a JSON string for embedding in HTML attributes.
|
|
186
|
+
* Strips non-serializable values (functions, symbols, children).
|
|
187
|
+
*/
|
|
188
|
+
function serializeIslandProps(props) {
|
|
189
|
+
const clean = {};
|
|
190
|
+
for (const [key, value] of Object.entries(props)) {
|
|
191
|
+
if (key === "children") continue;
|
|
192
|
+
if (typeof value === "function") continue;
|
|
193
|
+
if (typeof value === "symbol") continue;
|
|
194
|
+
if (value === void 0) continue;
|
|
195
|
+
clean[key] = value;
|
|
196
|
+
}
|
|
197
|
+
return JSON.stringify(clean);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/ssg.ts
|
|
202
|
+
/**
|
|
203
|
+
* Static Site Generation — pre-render routes to HTML files at build time.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* // ssg.ts (run with: bun run ssg.ts)
|
|
207
|
+
* import { createHandler } from "@pyreon/server"
|
|
208
|
+
* import { prerender } from "@pyreon/server"
|
|
209
|
+
* import { App } from "./src/App"
|
|
210
|
+
* import { routes } from "./src/routes"
|
|
211
|
+
*
|
|
212
|
+
* const handler = createHandler({ App, routes })
|
|
213
|
+
*
|
|
214
|
+
* await prerender({
|
|
215
|
+
* handler,
|
|
216
|
+
* paths: ["/", "/about", "/blog", "/blog/hello-world"],
|
|
217
|
+
* outDir: "dist",
|
|
218
|
+
* })
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* // Dynamic paths from a CMS or filesystem
|
|
222
|
+
* await prerender({
|
|
223
|
+
* handler,
|
|
224
|
+
* paths: async () => {
|
|
225
|
+
* const posts = await fetchAllPosts()
|
|
226
|
+
* return ["/", "/about", ...posts.map(p => `/blog/${p.slug}`)]
|
|
227
|
+
* },
|
|
228
|
+
* outDir: "dist",
|
|
229
|
+
* })
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
* Pre-render a list of routes to static HTML files.
|
|
233
|
+
*
|
|
234
|
+
* For each path:
|
|
235
|
+
* 1. Constructs a Request for the path
|
|
236
|
+
* 2. Calls the SSR handler to render to HTML
|
|
237
|
+
* 3. Writes the HTML to `outDir/<path>/index.html`
|
|
238
|
+
*
|
|
239
|
+
* The root path "/" becomes `outDir/index.html`.
|
|
240
|
+
* Paths like "/about" become `outDir/about/index.html`.
|
|
241
|
+
*/
|
|
242
|
+
async function prerender(options) {
|
|
243
|
+
const {
|
|
244
|
+
handler,
|
|
245
|
+
outDir,
|
|
246
|
+
origin = "http://localhost",
|
|
247
|
+
onPage
|
|
248
|
+
} = options;
|
|
249
|
+
const start = Date.now();
|
|
250
|
+
const paths = typeof options.paths === "function" ? await options.paths() : options.paths;
|
|
251
|
+
let pages = 0;
|
|
252
|
+
const errors = [];
|
|
253
|
+
async function renderPage(path) {
|
|
254
|
+
const url = new URL(path, origin);
|
|
255
|
+
const req = new Request(url.href);
|
|
256
|
+
const res = await Promise.race([handler(req), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */new Error(`Prerender timeout for "${path}" (30s)`)), 3e4))]);
|
|
257
|
+
if (!res.ok) {
|
|
258
|
+
errors.push({
|
|
259
|
+
path,
|
|
260
|
+
error: /* @__PURE__ */new Error(`HTTP ${res.status}`)
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const html = await res.text();
|
|
265
|
+
if (onPage) {
|
|
266
|
+
if ((await onPage(path, html)) === false) return;
|
|
267
|
+
}
|
|
268
|
+
const filePath = resolveOutputPath(outDir, path);
|
|
269
|
+
const resolvedOut = resolve(outDir);
|
|
270
|
+
if (!resolve(filePath).startsWith(resolvedOut)) {
|
|
271
|
+
errors.push({
|
|
272
|
+
path,
|
|
273
|
+
error: /* @__PURE__ */new Error(`Path traversal detected: "${path}"`)
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
await mkdir(dirname(filePath), {
|
|
278
|
+
recursive: true
|
|
279
|
+
});
|
|
280
|
+
await writeFile(filePath, html, "utf-8");
|
|
281
|
+
pages++;
|
|
282
|
+
}
|
|
283
|
+
const BATCH_SIZE = 10;
|
|
284
|
+
for (let i = 0; i < paths.length; i += BATCH_SIZE) {
|
|
285
|
+
const batch = paths.slice(i, i + BATCH_SIZE);
|
|
286
|
+
await Promise.all(batch.map(async path => {
|
|
287
|
+
try {
|
|
288
|
+
await renderPage(path);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
errors.push({
|
|
291
|
+
path,
|
|
292
|
+
error
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
pages,
|
|
299
|
+
errors,
|
|
300
|
+
elapsed: Date.now() - start
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function resolveOutputPath(outDir, path) {
|
|
304
|
+
if (path === "/") return join(outDir, "index.html");
|
|
305
|
+
if (path.endsWith(".html")) return join(outDir, path);
|
|
306
|
+
return join(outDir, path, "index.html");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
//#endregion
|
|
310
|
+
export { DEFAULT_TEMPLATE, buildScripts, createHandler, island, prerender, processTemplate };
|
|
311
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/html.ts","../../src/handler.ts","../../src/island.ts","../../src/ssg.ts"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,SAAgB,eAAA,CAAgB,QAAA,EAAkB,IAAA,EAA4B;EAC5E,OAAO,QAAA,CACJ,OAAA,CAAQ,oBAAA,EAAsB,IAAA,CAAK,IAAA,CAAK,CACxC,OAAA,CAAQ,mBAAA,EAAqB,IAAA,CAAK,GAAA,CAAI,CACtC,OAAA,CAAQ,uBAAA,EAAyB,IAAA,CAAK,OAAA,CAAQ;;;;;;;;;AAUnD,SAAgB,YAAA,CACd,WAAA,EACA,UAAA,EACQ;EACR,MAAM,KAAA,GAAkB,EAAE;EAE1B,IAAI,UAAA,IAAc,MAAA,CAAO,IAAA,CAAK,UAAA,CAAW,CAAC,MAAA,GAAS,CAAA,EAAG;IAEpD,MAAM,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,UAAA,CAAW,CAAC,OAAA,CAAQ,MAAA,EAAQ,MAAA,CAAO;IAC/D,KAAA,CAAM,IAAA,CAAK,yCAAyC,IAAA,YAAK,CAAW;;EAGtE,KAAA,CAAM,IAAA,CAAK,8BAA8B,WAAA,cAAY,CAAa;EAElE,OAAO,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO;;;;;ACU3B,SAAgB,aAAA,CAAc,OAAA,EAA8D;EAC1F,MAAM;IACJ,GAAA;IACA,MAAA;IACA,QAAA,GAAW,gBAAA;IACX,WAAA,GAAc,sBAAA;IACd,UAAA,GAAa,EAAE;IACf,IAAA,GAAO;EAAA,CAAA,GACL,OAAA;EAEJ,OAAO,eAAe,OAAA,CAAQ,GAAA,EAAiC;IAC7D,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,GAAA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