@inertia-node/ssr 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/dist/chunk-DBJRDFPF.js +64 -0
- package/dist/chunk-DBJRDFPF.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inertia Node Adapter contributors
|
|
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.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createServer
|
|
4
|
+
} from "http";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
async function loadRenderer(entry) {
|
|
7
|
+
const moduleUrl = entry.startsWith("file:") ? entry : pathToFileURL(entry).href;
|
|
8
|
+
const mod = await import(`${moduleUrl}?t=${Date.now()}`);
|
|
9
|
+
const render = mod.render ?? mod.default;
|
|
10
|
+
if (typeof render !== "function") {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"SSR entry must export a render function or default function"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return render;
|
|
16
|
+
}
|
|
17
|
+
async function createSsrServer(options) {
|
|
18
|
+
const render = await loadRenderer(options.entry);
|
|
19
|
+
return createServer(async (request, response) => {
|
|
20
|
+
if (request.method !== "POST" || request.url !== "/render") {
|
|
21
|
+
sendJson(response, 404, { error: "Not found" });
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const page = JSON.parse(await readBody(request));
|
|
26
|
+
sendJson(response, 200, await render(page));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
sendJson(response, 500, {
|
|
29
|
+
error: error instanceof Error ? error.message : String(error)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async function listen(options) {
|
|
35
|
+
const server = await createSsrServer(options);
|
|
36
|
+
const host = options.host ?? "127.0.0.1";
|
|
37
|
+
const port = options.port ?? 13714;
|
|
38
|
+
server.listen(port, host, () => {
|
|
39
|
+
console.log(`Inertia Node SSR server listening on http://${host}:${port}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function readBody(request) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
let body = "";
|
|
45
|
+
request.setEncoding("utf8");
|
|
46
|
+
request.on("data", (chunk) => {
|
|
47
|
+
body += chunk;
|
|
48
|
+
});
|
|
49
|
+
request.on("end", () => resolve(body));
|
|
50
|
+
request.on("error", reject);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function sendJson(response, status, payload) {
|
|
54
|
+
response.statusCode = status;
|
|
55
|
+
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
56
|
+
response.end(JSON.stringify(payload));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
loadRenderer,
|
|
61
|
+
createSsrServer,
|
|
62
|
+
listen
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-DBJRDFPF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n createServer,\n type IncomingMessage,\n type ServerResponse,\n} from \"node:http\";\nimport { pathToFileURL } from \"node:url\";\nimport type { InertiaPage, SsrResult } from \"@inertia-node/core\";\n\nexport type SsrRenderFunction = (\n page: InertiaPage,\n) => SsrResult | Promise<SsrResult>;\n\nexport interface SsrServerOptions {\n entry: string;\n host?: string;\n port?: number;\n}\n\nexport async function loadRenderer(entry: string): Promise<SsrRenderFunction> {\n const moduleUrl = entry.startsWith(\"file:\")\n ? entry\n : pathToFileURL(entry).href;\n const mod = (await import(`${moduleUrl}?t=${Date.now()}`)) as {\n default?: SsrRenderFunction;\n render?: SsrRenderFunction;\n };\n const render = mod.render ?? mod.default;\n\n if (typeof render !== \"function\") {\n throw new Error(\n \"SSR entry must export a render function or default function\",\n );\n }\n\n return render;\n}\n\nexport async function createSsrServer(options: SsrServerOptions) {\n const render = await loadRenderer(options.entry);\n\n return createServer(async (request, response) => {\n if (request.method !== \"POST\" || request.url !== \"/render\") {\n sendJson(response, 404, { error: \"Not found\" });\n return;\n }\n\n try {\n const page = JSON.parse(await readBody(request)) as InertiaPage;\n sendJson(response, 200, await render(page));\n } catch (error) {\n sendJson(response, 500, {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n });\n}\n\nexport async function listen(options: SsrServerOptions): Promise<void> {\n const server = await createSsrServer(options);\n const host = options.host ?? \"127.0.0.1\";\n const port = options.port ?? 13714;\n\n server.listen(port, host, () => {\n console.log(`Inertia Node SSR server listening on http://${host}:${port}`);\n });\n}\n\nfunction readBody(request: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n let body = \"\";\n request.setEncoding(\"utf8\");\n request.on(\"data\", (chunk) => {\n body += chunk;\n });\n request.on(\"end\", () => resolve(body));\n request.on(\"error\", reject);\n });\n}\n\nfunction sendJson(\n response: ServerResponse,\n status: number,\n payload: unknown,\n): void {\n response.statusCode = status;\n response.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n response.end(JSON.stringify(payload));\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,qBAAqB;AAa9B,eAAsB,aAAa,OAA2C;AAC5E,QAAM,YAAY,MAAM,WAAW,OAAO,IACtC,QACA,cAAc,KAAK,EAAE;AACzB,QAAM,MAAO,MAAM,OAAO,GAAG,SAAS,MAAM,KAAK,IAAI,CAAC;AAItD,QAAM,SAAS,IAAI,UAAU,IAAI;AAEjC,MAAI,OAAO,WAAW,YAAY;AAChC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,eAAsB,gBAAgB,SAA2B;AAC/D,QAAM,SAAS,MAAM,aAAa,QAAQ,KAAK;AAE/C,SAAO,aAAa,OAAO,SAAS,aAAa;AAC/C,QAAI,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW;AAC1D,eAAS,UAAU,KAAK,EAAE,OAAO,YAAY,CAAC;AAC9C;AAAA,IACF;AAEA,QAAI;AACF,YAAM,OAAO,KAAK,MAAM,MAAM,SAAS,OAAO,CAAC;AAC/C,eAAS,UAAU,KAAK,MAAM,OAAO,IAAI,CAAC;AAAA,IAC5C,SAAS,OAAO;AACd,eAAS,UAAU,KAAK;AAAA,QACtB,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,OAAO,SAA0C;AACrE,QAAM,SAAS,MAAM,gBAAgB,OAAO;AAC5C,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,OAAO,QAAQ,QAAQ;AAE7B,SAAO,OAAO,MAAM,MAAM,MAAM;AAC9B,YAAQ,IAAI,+CAA+C,IAAI,IAAI,IAAI,EAAE;AAAA,EAC3E,CAAC;AACH;AAEA,SAAS,SAAS,SAA2C;AAC3D,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO;AACX,YAAQ,YAAY,MAAM;AAC1B,YAAQ,GAAG,QAAQ,CAAC,UAAU;AAC5B,cAAQ;AAAA,IACV,CAAC;AACD,YAAQ,GAAG,OAAO,MAAM,QAAQ,IAAI,CAAC;AACrC,YAAQ,GAAG,SAAS,MAAM;AAAA,EAC5B,CAAC;AACH;AAEA,SAAS,SACP,UACA,QACA,SACM;AACN,WAAS,aAAa;AACtB,WAAS,UAAU,gBAAgB,iCAAiC;AACpE,WAAS,IAAI,KAAK,UAAU,OAAO,CAAC;AACtC;","names":[]}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
listen
|
|
4
|
+
} from "./chunk-DBJRDFPF.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
var args = /* @__PURE__ */ new Map();
|
|
8
|
+
for (let index = 2; index < process.argv.length; index += 2) {
|
|
9
|
+
const key = process.argv[index]?.replace(/^--/, "");
|
|
10
|
+
const value = process.argv[index + 1];
|
|
11
|
+
if (key && value) {
|
|
12
|
+
args.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var entry = args.get("entry");
|
|
16
|
+
if (!entry) {
|
|
17
|
+
console.error(
|
|
18
|
+
"Usage: inertia-node-ssr --entry dist/ssr.js [--host 127.0.0.1] [--port 13714]"
|
|
19
|
+
);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
await listen({
|
|
23
|
+
entry,
|
|
24
|
+
host: args.get("host") ?? "127.0.0.1",
|
|
25
|
+
port: Number(args.get("port") ?? 13714)
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { listen } from \"./index.js\";\n\nconst args = new Map<string, string>();\n\nfor (let index = 2; index < process.argv.length; index += 2) {\n const key = process.argv[index]?.replace(/^--/, \"\");\n const value = process.argv[index + 1];\n\n if (key && value) {\n args.set(key, value);\n }\n}\n\nconst entry = args.get(\"entry\");\n\nif (!entry) {\n console.error(\n \"Usage: inertia-node-ssr --entry dist/ssr.js [--host 127.0.0.1] [--port 13714]\",\n );\n process.exit(1);\n}\n\nawait listen({\n entry,\n host: args.get(\"host\") ?? \"127.0.0.1\",\n port: Number(args.get(\"port\") ?? 13714),\n});\n"],"mappings":";;;;;;AAGA,IAAM,OAAO,oBAAI,IAAoB;AAErC,SAAS,QAAQ,GAAG,QAAQ,QAAQ,KAAK,QAAQ,SAAS,GAAG;AAC3D,QAAM,MAAM,QAAQ,KAAK,KAAK,GAAG,QAAQ,OAAO,EAAE;AAClD,QAAM,QAAQ,QAAQ,KAAK,QAAQ,CAAC;AAEpC,MAAI,OAAO,OAAO;AAChB,SAAK,IAAI,KAAK,KAAK;AAAA,EACrB;AACF;AAEA,IAAM,QAAQ,KAAK,IAAI,OAAO;AAE9B,IAAI,CAAC,OAAO;AACV,UAAQ;AAAA,IACN;AAAA,EACF;AACA,UAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,OAAO;AAAA,EACX;AAAA,EACA,MAAM,KAAK,IAAI,MAAM,KAAK;AAAA,EAC1B,MAAM,OAAO,KAAK,IAAI,MAAM,KAAK,KAAK;AACxC,CAAC;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import { InertiaPage, SsrResult } from '@inertia-node/core';
|
|
4
|
+
|
|
5
|
+
type SsrRenderFunction = (page: InertiaPage) => SsrResult | Promise<SsrResult>;
|
|
6
|
+
interface SsrServerOptions {
|
|
7
|
+
entry: string;
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
}
|
|
11
|
+
declare function loadRenderer(entry: string): Promise<SsrRenderFunction>;
|
|
12
|
+
declare function createSsrServer(options: SsrServerOptions): Promise<http.Server<typeof IncomingMessage, typeof ServerResponse>>;
|
|
13
|
+
declare function listen(options: SsrServerOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
export { type SsrRenderFunction, type SsrServerOptions, createSsrServer, listen, loadRenderer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inertia-node/ssr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Standalone SSR server for Inertia Node adapters.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Inertia Node Adapter contributors",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/inertia-node/inertia-node-adapter.git",
|
|
11
|
+
"directory": "packages/ssr"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/inertia-node/inertia-node-adapter#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/inertia-node/inertia-node-adapter/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"inertia",
|
|
19
|
+
"inertiajs",
|
|
20
|
+
"ssr",
|
|
21
|
+
"node",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"inertia-node-ssr": "./dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@inertia-node/core": "0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup src/index.ts src/cli.ts --format esm --dts --sourcemap",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
}
|
|
49
|
+
}
|