@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Vit Bokisch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @pyreon/server
|
|
2
|
+
|
|
3
|
+
SSR handler, static site generation, and island architecture for Pyreon.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## SSR
|
|
12
|
+
|
|
13
|
+
Create a request handler that renders your Pyreon app on the server:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createHandler } from "@pyreon/server"
|
|
17
|
+
import { App } from "./App"
|
|
18
|
+
import { routes } from "./routes"
|
|
19
|
+
|
|
20
|
+
const handler = createHandler({
|
|
21
|
+
App,
|
|
22
|
+
routes,
|
|
23
|
+
template: await Bun.file("index.html").text(),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
Bun.serve({ fetch: handler, port: 3000 })
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## SSG (Static Site Generation)
|
|
30
|
+
|
|
31
|
+
Pre-render pages to static HTML files:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createHandler, prerender } from "@pyreon/server"
|
|
35
|
+
|
|
36
|
+
const handler = createHandler({ App, routes })
|
|
37
|
+
const result = await prerender({
|
|
38
|
+
handler,
|
|
39
|
+
paths: ["/", "/about", "/blog"],
|
|
40
|
+
outDir: "dist",
|
|
41
|
+
})
|
|
42
|
+
console.log(`Generated ${result.pages} pages in ${result.elapsed}ms`)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Islands
|
|
46
|
+
|
|
47
|
+
Render mostly-static pages with interactive islands that hydrate independently:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// Server
|
|
51
|
+
import { island } from "@pyreon/server"
|
|
52
|
+
|
|
53
|
+
const Counter = island(() => import("./Counter"), {
|
|
54
|
+
name: "Counter",
|
|
55
|
+
hydrate: "visible", // load | idle | visible | media(query) | never
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// Client entry
|
|
61
|
+
import { startClient, hydrateIslands } from "@pyreon/server/client"
|
|
62
|
+
|
|
63
|
+
// Full app hydration
|
|
64
|
+
startClient({ App, routes, container: "#app" })
|
|
65
|
+
|
|
66
|
+
// Or island-only hydration
|
|
67
|
+
hydrateIslands({
|
|
68
|
+
Counter: () => import("./Counter"),
|
|
69
|
+
Search: () => import("./Search"),
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API
|
|
74
|
+
|
|
75
|
+
### Server Exports (`@pyreon/server`)
|
|
76
|
+
|
|
77
|
+
- `createHandler(options: HandlerOptions)` -- create an SSR request handler
|
|
78
|
+
- `prerender(options: PrerenderOptions)` -- generate static HTML files
|
|
79
|
+
- `island(loader, options: IslandOptions)` -- define an island component
|
|
80
|
+
- `processTemplate(template, data)` -- inject rendered HTML into an HTML template
|
|
81
|
+
- `buildScripts(data)` -- generate script tags for hydration
|
|
82
|
+
- `DEFAULT_TEMPLATE` -- built-in HTML template
|
|
83
|
+
|
|
84
|
+
### Client Exports (`@pyreon/server/client`)
|
|
85
|
+
|
|
86
|
+
- `startClient(options: StartClientOptions)` -- hydrate a full SSR app
|
|
87
|
+
- `hydrateIslands(registry)` -- hydrate island components on the page
|
|
88
|
+
|
|
89
|
+
### Types
|
|
90
|
+
|
|
91
|
+
`HandlerOptions`, `PrerenderOptions`, `PrerenderResult`, `IslandOptions`, `IslandMeta`, `HydrationStrategy`, `Middleware`, `MiddlewareContext`, `TemplateData`, `StartClientOptions`
|