@inertia-node/ssr 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +211 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # @inertia-node/ssr
2
+
3
+ Standalone SSR server for Inertia Node adapters.
4
+
5
+ `@inertia-node/ssr` runs a small HTTP server that receives an Inertia page object, calls your SSR renderer, and returns rendered HTML fragments. It is designed to be used by `@inertia-node/express`, `@inertia-node/nest`, `@inertia-node/nest-fastify`, or any custom adapter built on `@inertia-node/core`.
6
+
7
+ ## Features
8
+
9
+ - Provides the `inertia-node-ssr` CLI.
10
+ - Provides a programmatic SSR server API.
11
+ - Loads a renderer from a local path or `file:` URL.
12
+ - Accepts JSON page payloads through `POST /render`.
13
+ - Supports renderer modules with either a default export or named `render` export.
14
+ - Returns the shared `SsrResult` shape used by `@inertia-node/core`.
15
+
16
+ ## Installation
17
+
18
+ ```sh
19
+ pnpm add @inertia-node/ssr
20
+ ```
21
+
22
+ ```sh
23
+ npm install @inertia-node/ssr
24
+ ```
25
+
26
+ Node.js requirement:
27
+
28
+ - `>=22`
29
+
30
+ ## Quick Start
31
+
32
+ ### 1. Create an SSR Entry
33
+
34
+ ```tsx
35
+ // ssr-entry.tsx
36
+ import { createInertiaApp } from "@inertiajs/react";
37
+ import { renderToString } from "react-dom/server";
38
+
39
+ export default async function render(page) {
40
+ const result = await createInertiaApp({
41
+ page,
42
+ render: (element) => renderToString(element),
43
+ resolve: (name) => {
44
+ const pages = import.meta.glob("./Pages/**/*.tsx", { eager: true });
45
+ const module = pages[`./Pages/${name}.tsx`];
46
+ return module.default;
47
+ },
48
+ setup: ({ App, props }) => <App {...props} />,
49
+ });
50
+
51
+ return {
52
+ head:
53
+ typeof result.head === "function" ? result.head() : String(result.head),
54
+ body: String(result.body),
55
+ };
56
+ }
57
+ ```
58
+
59
+ ### 2. Build the SSR Entry
60
+
61
+ Use your normal app build tool to produce a server-renderable ESM file:
62
+
63
+ ```sh
64
+ pnpm build
65
+ ```
66
+
67
+ The output path must point to the compiled SSR entry, for example `dist/ssr-entry.js`.
68
+
69
+ ### 3. Start the SSR Server
70
+
71
+ ```sh
72
+ inertia-node-ssr --entry dist/ssr-entry.js --host 127.0.0.1 --port 13714
73
+ ```
74
+
75
+ ### 4. Enable SSR in an Adapter
76
+
77
+ ```ts
78
+ inertiaMiddleware({
79
+ ssr: {
80
+ enabled: true,
81
+ url: "http://127.0.0.1:13714/render",
82
+ timeoutMs: 1500,
83
+ },
84
+ });
85
+ ```
86
+
87
+ ## CLI
88
+
89
+ ```sh
90
+ inertia-node-ssr --entry <path> [--host 127.0.0.1] [--port 13714]
91
+ ```
92
+
93
+ Arguments:
94
+
95
+ - `--entry`: required path to the compiled renderer module.
96
+ - `--host`: optional host, defaults to `127.0.0.1`.
97
+ - `--port`: optional port, defaults to `13714`.
98
+
99
+ ## Programmatic API
100
+
101
+ ```ts
102
+ import { createSsrServer, listen, loadRenderer } from "@inertia-node/ssr";
103
+
104
+ const render = await loadRenderer("dist/ssr-entry.js");
105
+ const result = await render(page);
106
+
107
+ const server = await createSsrServer({
108
+ entry: "dist/ssr-entry.js",
109
+ host: "127.0.0.1",
110
+ port: 13714,
111
+ });
112
+
113
+ await listen({
114
+ entry: "dist/ssr-entry.js",
115
+ host: "127.0.0.1",
116
+ port: 13714,
117
+ });
118
+ ```
119
+
120
+ ## HTTP Contract
121
+
122
+ The server accepts only:
123
+
124
+ ```txt
125
+ POST /render
126
+ ```
127
+
128
+ The request body must be an Inertia page object:
129
+
130
+ ```json
131
+ {
132
+ "component": "Dashboard/Index",
133
+ "props": {
134
+ "user": {
135
+ "name": "Ada"
136
+ }
137
+ },
138
+ "url": "/dashboard",
139
+ "version": "1"
140
+ }
141
+ ```
142
+
143
+ The response must be compatible with `SsrResult`:
144
+
145
+ ```json
146
+ {
147
+ "head": "<title>Dashboard</title>",
148
+ "body": "<div>...</div>"
149
+ }
150
+ ```
151
+
152
+ ## Renderer Exports
153
+
154
+ Renderer modules can export either:
155
+
156
+ ```ts
157
+ export default async function render(page) {
158
+ return {
159
+ head: "",
160
+ body: "",
161
+ };
162
+ }
163
+ ```
164
+
165
+ or:
166
+
167
+ ```ts
168
+ export async function render(page) {
169
+ return {
170
+ head: "",
171
+ body: "",
172
+ };
173
+ }
174
+ ```
175
+
176
+ ## Debugging SSR
177
+
178
+ Test the SSR server directly:
179
+
180
+ ```sh
181
+ curl -X POST http://127.0.0.1:13714/render \
182
+ -H "Content-Type: application/json" \
183
+ -d '{"component":"Dashboard/Index","props":{},"url":"/dashboard","version":"1"}'
184
+ ```
185
+
186
+ If SSR is working, the response should contain rendered `head` and `body` strings.
187
+
188
+ While debugging an adapter integration, set:
189
+
190
+ ```ts
191
+ ssr: {
192
+ enabled: true,
193
+ throwOnError: true,
194
+ }
195
+ ```
196
+
197
+ This makes SSR failures visible instead of silently falling back to the client-side shell.
198
+
199
+ ## Exports
200
+
201
+ - `loadRenderer(entry)`
202
+ - `createSsrServer(options)`
203
+ - `listen(options)`
204
+ - `SsrRenderFunction`
205
+ - `SsrServerOptions`
206
+
207
+ ## Documentation
208
+
209
+ - Repository: https://github.com/inertia-node/inertia-node-adapter
210
+ - SSR docs: https://github.com/inertia-node/inertia-node-adapter/blob/main/docs/ssr.md
211
+ - Deployment docs: https://github.com/inertia-node/inertia-node-adapter/blob/main/docs/deployment.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertia-node/ssr",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Standalone SSR server for Inertia Node adapters.",
5
5
  "license": "MIT",
6
6
  "author": "Inertia Node Adapter contributors",
@@ -34,10 +34,11 @@
34
34
  }
35
35
  },
36
36
  "files": [
37
- "dist"
37
+ "dist",
38
+ "README.md"
38
39
  ],
39
40
  "dependencies": {
40
- "@inertia-node/core": "0.1.0"
41
+ "@inertia-node/core": "0.1.1"
41
42
  },
42
43
  "engines": {
43
44
  "node": ">=22"