reactivated 0.37.1-a2123 → 0.37.1-a2139
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/build.client.d.mts +2 -0
- package/dist/build.client.mjs +3 -0
- package/dist/build.client.mjs.map +1 -1
- package/dist/vite.mjs +2 -2
- package/package.json +1 -2
- package/src/build.client.mts +3 -0
- package/src/vite.mts +2 -2
- package/dist/renderer.d.ts +0 -27
- package/dist/renderer.js +0 -123
- package/dist/renderer.js.map +0 -1
- package/src/renderer.tsx +0 -191
package/dist/build.client.d.mts
CHANGED
|
@@ -28,6 +28,7 @@ declare const clientConfig: {
|
|
|
28
28
|
"@reactivated": string;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
base: string;
|
|
31
32
|
};
|
|
32
33
|
declare const rendererConfig: {
|
|
33
34
|
ssr: {
|
|
@@ -58,6 +59,7 @@ declare const rendererConfig: {
|
|
|
58
59
|
"@reactivated": string;
|
|
59
60
|
};
|
|
60
61
|
};
|
|
62
|
+
base: string;
|
|
61
63
|
};
|
|
62
64
|
export type ClientConfig = typeof clientConfig;
|
|
63
65
|
export type RendererConfig = typeof rendererConfig;
|
package/dist/build.client.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import path from "path";
|
|
|
7
7
|
import { define } from "./conf.js";
|
|
8
8
|
import * as esbuild from "esbuild";
|
|
9
9
|
import { promises as fs } from "fs";
|
|
10
|
+
const base = process.env.BASE ?? "/";
|
|
10
11
|
const identifiers = "short";
|
|
11
12
|
const clientConfig = {
|
|
12
13
|
define: define(),
|
|
@@ -34,6 +35,7 @@ const clientConfig = {
|
|
|
34
35
|
"@reactivated": path.resolve(process.cwd(), "./node_modules/_reactivated"),
|
|
35
36
|
},
|
|
36
37
|
},
|
|
38
|
+
base,
|
|
37
39
|
};
|
|
38
40
|
const otherExternals = [];
|
|
39
41
|
const external = [
|
|
@@ -70,6 +72,7 @@ const rendererConfig = {
|
|
|
70
72
|
"@reactivated": path.resolve(process.cwd(), "./node_modules/_reactivated"),
|
|
71
73
|
},
|
|
72
74
|
},
|
|
75
|
+
base,
|
|
73
76
|
};
|
|
74
77
|
await build(clientConfig);
|
|
75
78
|
await build(rendererConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.client.mjs","sourceRoot":"","sources":["../src/build.client.mts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAC,oBAAoB,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAe,KAAK,EAAC,MAAM,MAAM,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,MAAM,EAAU,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,QAAQ,IAAI,EAAE,EAAC,MAAM,IAAI,CAAC;AAElC,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,MAAM,YAAY,GAAG;IACjB,MAAM,EAAE,MAAM,EAAE;IAChB,KAAK,EAAE;QACH,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,IAAI;QACjB,MAAM,EAAE,aAAa;QACrB,QAAQ,EAAE,KAAK;QACf,aAAa,EAAE;YACX,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE;gBACJ,oBAAoB,EAAE,IAAI;gBAC1B,cAAc,EAAE,WAAW;gBAC3B,cAAc,EAAE,WAAW;gBAC3B,cAAc,EAAE,cAAc;aACjC;SACJ;KACJ;IAED,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,oBAAoB,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC;IACvD,OAAO,EAAE;QACL,KAAK,EAAE;YACH,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CA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5B,gFAAgF;AAChF,kFAAkF;AAClF,MAAM,OAAO,CAAC,KAAK,CAAC;IAChB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,CAAC,0CAA0C,CAAC;IACzD,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,yCAAyC;CACrD,CAAC,CAAC;AAEH,MAAM,EAAE,CAAC,MAAM,CAAC,0CAA0C,CAAC,CAAC;AAC5D,MAAM,EAAE,CAAC,MAAM,CAAC,8CAA8C,CAAC,CAAC"}
|
package/dist/vite.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { define } from "./conf.js";
|
|
|
7
7
|
import { cjsInterop } from "vite-plugin-cjs-interop";
|
|
8
8
|
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
9
9
|
const isProduction = process.env.NODE_ENV === "production";
|
|
10
|
-
const port = process.env.REACTIVATED_VITE_PORT
|
|
11
|
-
const base = process.env.BASE
|
|
10
|
+
const port = process.env.REACTIVATED_VITE_PORT ?? 5173;
|
|
11
|
+
const base = process.env.BASE ?? "/";
|
|
12
12
|
const escapedBase = base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
13
|
const reactivatedEndpoint = "/_reactivated/".replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
14
|
const app = express();
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactivated",
|
|
3
|
-
"version": "0.37.1-
|
|
3
|
+
"version": "0.37.1-a2139",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/index.js",
|
|
8
|
-
"./dist/renderer": "./dist/renderer.js",
|
|
9
8
|
"./dist/forms": "./dist/forms/index.js",
|
|
10
9
|
"./dist/context": "./dist/context.js",
|
|
11
10
|
"./dist/conf": "./dist/conf.js",
|
package/src/build.client.mts
CHANGED
|
@@ -9,6 +9,7 @@ import {define, Options} from "./conf.js";
|
|
|
9
9
|
import * as esbuild from "esbuild";
|
|
10
10
|
import {promises as fs} from "fs";
|
|
11
11
|
|
|
12
|
+
const base = process.env.BASE ?? "/";
|
|
12
13
|
const identifiers = "short";
|
|
13
14
|
|
|
14
15
|
const clientConfig = {
|
|
@@ -38,6 +39,7 @@ const clientConfig = {
|
|
|
38
39
|
"@reactivated": path.resolve(process.cwd(), "./node_modules/_reactivated"),
|
|
39
40
|
},
|
|
40
41
|
},
|
|
42
|
+
base,
|
|
41
43
|
} satisfies InlineConfig;
|
|
42
44
|
|
|
43
45
|
const otherExternals: string[] = [];
|
|
@@ -77,6 +79,7 @@ const rendererConfig = {
|
|
|
77
79
|
"@reactivated": path.resolve(process.cwd(), "./node_modules/_reactivated"),
|
|
78
80
|
},
|
|
79
81
|
},
|
|
82
|
+
base,
|
|
80
83
|
} satisfies InlineConfig;
|
|
81
84
|
|
|
82
85
|
export type ClientConfig = typeof clientConfig;
|
package/src/vite.mts
CHANGED
|
@@ -18,8 +18,8 @@ import {Helmet, HelmetProvider, HelmetServerState} from "react-helmet-async";
|
|
|
18
18
|
import {vanillaExtractPlugin} from "@vanilla-extract/vite-plugin";
|
|
19
19
|
|
|
20
20
|
const isProduction = process.env.NODE_ENV === "production";
|
|
21
|
-
const port = process.env.REACTIVATED_VITE_PORT
|
|
22
|
-
const base = process.env.BASE
|
|
21
|
+
const port = process.env.REACTIVATED_VITE_PORT ?? 5173;
|
|
22
|
+
const base = process.env.BASE ?? "/";
|
|
23
23
|
const escapedBase = base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
24
|
const reactivatedEndpoint = "/_reactivated/".replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25
25
|
|
package/dist/renderer.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import http from "http";
|
|
4
|
-
import { HelmetServerState } from "react-helmet-async";
|
|
5
|
-
export declare const BODY_SIZE_LIMIT = "100000000k";
|
|
6
|
-
export declare const renderPage: ({ html, helmet, context, props, }: {
|
|
7
|
-
html: string;
|
|
8
|
-
helmet: HelmetServerState;
|
|
9
|
-
context: any;
|
|
10
|
-
props: any;
|
|
11
|
-
}) => string;
|
|
12
|
-
type Result = {
|
|
13
|
-
status: "success";
|
|
14
|
-
rendered: string;
|
|
15
|
-
} | {
|
|
16
|
-
status: "error";
|
|
17
|
-
error: any;
|
|
18
|
-
};
|
|
19
|
-
export declare const render: ({ context, props, }: {
|
|
20
|
-
context: any;
|
|
21
|
-
props: any;
|
|
22
|
-
}) => Promise<Result>;
|
|
23
|
-
export declare const simpleRender: () => void;
|
|
24
|
-
export declare const serverRender: (body: Buffer) => Promise<Result>;
|
|
25
|
-
export declare const SOCKET_PATH: string;
|
|
26
|
-
export declare const server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
27
|
-
export {};
|
package/dist/renderer.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import ReactDOMServer from "react-dom/server";
|
|
5
|
-
import { HelmetProvider } from "react-helmet-async";
|
|
6
|
-
// TODO: WHAT DOES THIS NEED TO BE? Even 100k was super fragile and a 10 choice field broke it.
|
|
7
|
-
export const BODY_SIZE_LIMIT = "100000000k";
|
|
8
|
-
export const renderPage = ({ html, helmet, context, props, }) => {
|
|
9
|
-
const scriptNonce = context.request.csp_nonce
|
|
10
|
-
? `nonce="${context.request.csp_nonce}"`
|
|
11
|
-
: "";
|
|
12
|
-
return `
|
|
13
|
-
<!DOCTYPE html>
|
|
14
|
-
<html ${helmet.htmlAttributes.toString()}>
|
|
15
|
-
<head>
|
|
16
|
-
<script ${scriptNonce}>
|
|
17
|
-
// These go first because scripts below need them.
|
|
18
|
-
// WARNING: See the following for security issues around embedding JSON in HTML:
|
|
19
|
-
// http://redux.js.org/recipes/ServerRendering.html#security-considerations
|
|
20
|
-
window.__PRELOADED_PROPS__ = ${JSON.stringify(props).replace(/</g, "\\u003c")}
|
|
21
|
-
window.__PRELOADED_CONTEXT__ = ${JSON.stringify(context).replace(/</g, "\\u003c")}
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
${helmet.base.toString()}
|
|
25
|
-
${helmet.link.toString()}
|
|
26
|
-
${helmet.meta.toString()}
|
|
27
|
-
${helmet.noscript.toString()}
|
|
28
|
-
${helmet.script.toString()}
|
|
29
|
-
${helmet.style.toString()}
|
|
30
|
-
${helmet.title.toString()}
|
|
31
|
-
</head>
|
|
32
|
-
<body ${helmet.bodyAttributes.toString()}>
|
|
33
|
-
<div id="root">${html}</div>
|
|
34
|
-
</body>
|
|
35
|
-
</html>`;
|
|
36
|
-
};
|
|
37
|
-
const PATHS = ["/", "/form/"];
|
|
38
|
-
export const render = async ({ context, props, }) => {
|
|
39
|
-
const defaultConfiguration = {
|
|
40
|
-
render: (content) => Promise.resolve(content),
|
|
41
|
-
};
|
|
42
|
-
let customConfiguration = null;
|
|
43
|
-
try {
|
|
44
|
-
customConfiguration = await import(
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
"_reactivated/conf.mjs");
|
|
47
|
-
}
|
|
48
|
-
catch (error) { }
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
const { Provider, getTemplate } = await import("_reactivated/index.tsx");
|
|
51
|
-
try {
|
|
52
|
-
const Template = getTemplate(context);
|
|
53
|
-
const helmetContext = {};
|
|
54
|
-
const content = (React.createElement(HelmetProvider, { context: helmetContext },
|
|
55
|
-
React.createElement(Provider, { value: context },
|
|
56
|
-
React.createElement(Template, { ...props }))));
|
|
57
|
-
const rendered = ReactDOMServer.renderToString(await (customConfiguration?.default?.render ?? defaultConfiguration.render)(content));
|
|
58
|
-
const { helmet } = helmetContext;
|
|
59
|
-
return {
|
|
60
|
-
status: "success",
|
|
61
|
-
rendered: renderPage({
|
|
62
|
-
html: rendered,
|
|
63
|
-
helmet,
|
|
64
|
-
props,
|
|
65
|
-
context,
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
status: "success",
|
|
70
|
-
rendered,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
return { status: "error", error };
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
export const simpleRender = () => {
|
|
78
|
-
const input = fs.readFileSync(0);
|
|
79
|
-
const { context, props } = JSON.parse(input.toString("utf8"));
|
|
80
|
-
process.stdout.write(JSON.stringify(render({ context, props })));
|
|
81
|
-
};
|
|
82
|
-
export const serverRender = (body) => {
|
|
83
|
-
const { context, props } = JSON.parse(body.toString("utf8"));
|
|
84
|
-
return render({ context, props });
|
|
85
|
-
};
|
|
86
|
-
const OK_RESPONSE = 200;
|
|
87
|
-
const ERROR_REPONSE = 500;
|
|
88
|
-
// Relative path to keep it under 100 characters.
|
|
89
|
-
// See: https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars
|
|
90
|
-
export const SOCKET_PATH = process.env.REACTIVATED_SOCKET ?? `node_modules/_reactivated/reactivated.sock`;
|
|
91
|
-
export const server = http.createServer((req, res) => {
|
|
92
|
-
let body = Buffer.from("");
|
|
93
|
-
req.on("data", (chunk) => {
|
|
94
|
-
body = Buffer.concat([body, chunk]);
|
|
95
|
-
});
|
|
96
|
-
req.on("end", async () => {
|
|
97
|
-
const result = await serverRender(body);
|
|
98
|
-
if (result.status === "success") {
|
|
99
|
-
res.writeHead(OK_RESPONSE, { "Content-Type": "text/html; charset=utf-8" });
|
|
100
|
-
res.end(result.rendered);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
res.writeHead(ERROR_REPONSE, { "Content-Type": "application/json" });
|
|
104
|
-
res.end(JSON.stringify(result.error, Object.getOwnPropertyNames(result.error)));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
if (fs.existsSync(SOCKET_PATH)) {
|
|
109
|
-
fs.unlinkSync(SOCKET_PATH);
|
|
110
|
-
}
|
|
111
|
-
server.listen(SOCKET_PATH, () => {
|
|
112
|
-
const address = server.address();
|
|
113
|
-
if (address == null) {
|
|
114
|
-
throw new Error();
|
|
115
|
-
}
|
|
116
|
-
else if (typeof address === "string") {
|
|
117
|
-
process.stdout.write(`RENDERER:${address}:LISTENING`);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
process.stdout.write(`RENDERER:${address.port.toString()}:LISTENING`);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
//# sourceMappingURL=renderer.js.map
|
package/dist/renderer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAS,cAAc,EAAoB,MAAM,oBAAoB,CAAC;AAK7E,+FAA+F;AAC/F,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,KAAK,GAMR,EAAE,EAAE;IACD,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS;QACzC,CAAC,CAAC,UAAU,OAAO,CAAC,OAAO,CAAC,SAAS,GAAG;QACxC,CAAC,CAAC,EAAE,CAAC;IACT,OAAO;;QAEH,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE;;kBAEtB,WAAW;;;;2CAIc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CACxD,IAAI,EACJ,SAAS,CACZ;6CACgC,IAAI,CAAC,S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AAC,CAAC;CAC9B;AAED,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,IAAI,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,EAAE,CAAC;KACrB;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,YAAY,CAAC,CAAC;KACzD;SAAM;QACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;KACzE;AACL,CAAC,CAAC,CAAC"}
|
package/src/renderer.tsx
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import {compile} from "json-schema-to-typescript";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import React from "react";
|
|
6
|
-
import ReactDOMServer from "react-dom/server";
|
|
7
|
-
import {Helmet, HelmetProvider, HelmetServerState} from "react-helmet-async";
|
|
8
|
-
|
|
9
|
-
import {Options} from "./conf";
|
|
10
|
-
import {Settings} from "./models";
|
|
11
|
-
|
|
12
|
-
// TODO: WHAT DOES THIS NEED TO BE? Even 100k was super fragile and a 10 choice field broke it.
|
|
13
|
-
export const BODY_SIZE_LIMIT = "100000000k";
|
|
14
|
-
|
|
15
|
-
export const renderPage = ({
|
|
16
|
-
html,
|
|
17
|
-
helmet,
|
|
18
|
-
context,
|
|
19
|
-
props,
|
|
20
|
-
}: {
|
|
21
|
-
html: string;
|
|
22
|
-
helmet: HelmetServerState;
|
|
23
|
-
context: any;
|
|
24
|
-
props: any;
|
|
25
|
-
}) => {
|
|
26
|
-
const scriptNonce = context.request.csp_nonce
|
|
27
|
-
? `nonce="${context.request.csp_nonce}"`
|
|
28
|
-
: "";
|
|
29
|
-
return `
|
|
30
|
-
<!DOCTYPE html>
|
|
31
|
-
<html ${helmet.htmlAttributes.toString()}>
|
|
32
|
-
<head>
|
|
33
|
-
<script ${scriptNonce}>
|
|
34
|
-
// These go first because scripts below need them.
|
|
35
|
-
// WARNING: See the following for security issues around embedding JSON in HTML:
|
|
36
|
-
// http://redux.js.org/recipes/ServerRendering.html#security-considerations
|
|
37
|
-
window.__PRELOADED_PROPS__ = ${JSON.stringify(props).replace(
|
|
38
|
-
/</g,
|
|
39
|
-
"\\u003c",
|
|
40
|
-
)}
|
|
41
|
-
window.__PRELOADED_CONTEXT__ = ${JSON.stringify(context).replace(
|
|
42
|
-
/</g,
|
|
43
|
-
"\\u003c",
|
|
44
|
-
)}
|
|
45
|
-
</script>
|
|
46
|
-
|
|
47
|
-
${helmet.base.toString()}
|
|
48
|
-
${helmet.link.toString()}
|
|
49
|
-
${helmet.meta.toString()}
|
|
50
|
-
${helmet.noscript.toString()}
|
|
51
|
-
${helmet.script.toString()}
|
|
52
|
-
${helmet.style.toString()}
|
|
53
|
-
${helmet.title.toString()}
|
|
54
|
-
</head>
|
|
55
|
-
<body ${helmet.bodyAttributes.toString()}>
|
|
56
|
-
<div id="root">${html}</div>
|
|
57
|
-
</body>
|
|
58
|
-
</html>`;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const PATHS = ["/", "/form/"];
|
|
62
|
-
|
|
63
|
-
type Result =
|
|
64
|
-
| {
|
|
65
|
-
status: "success";
|
|
66
|
-
rendered: string;
|
|
67
|
-
}
|
|
68
|
-
| {
|
|
69
|
-
status: "error";
|
|
70
|
-
error: any;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const render = async ({
|
|
74
|
-
context,
|
|
75
|
-
props,
|
|
76
|
-
}: {
|
|
77
|
-
context: any;
|
|
78
|
-
props: any;
|
|
79
|
-
}): Promise<Result> => {
|
|
80
|
-
const defaultConfiguration = {
|
|
81
|
-
render: (content) => Promise.resolve(content),
|
|
82
|
-
} satisfies Options;
|
|
83
|
-
|
|
84
|
-
let customConfiguration: {default?: Options} | null = null;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
customConfiguration = await import(
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
"_reactivated/conf.mjs"
|
|
90
|
-
);
|
|
91
|
-
} catch (error: unknown) {}
|
|
92
|
-
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
const {Provider, getTemplate} = await import("_reactivated/index.tsx");
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const Template = getTemplate(context);
|
|
98
|
-
const helmetContext = {} as {helmet: HelmetServerState};
|
|
99
|
-
|
|
100
|
-
const content = (
|
|
101
|
-
<HelmetProvider context={helmetContext}>
|
|
102
|
-
<Provider value={context}>
|
|
103
|
-
<Template {...props} />
|
|
104
|
-
</Provider>
|
|
105
|
-
</HelmetProvider>
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const rendered = ReactDOMServer.renderToString(
|
|
109
|
-
await (customConfiguration?.default?.render ?? defaultConfiguration.render)(
|
|
110
|
-
content,
|
|
111
|
-
),
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const {helmet} = helmetContext;
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
status: "success",
|
|
118
|
-
rendered: renderPage({
|
|
119
|
-
html: rendered,
|
|
120
|
-
helmet,
|
|
121
|
-
props,
|
|
122
|
-
context,
|
|
123
|
-
}),
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
status: "success",
|
|
128
|
-
rendered,
|
|
129
|
-
};
|
|
130
|
-
} catch (error) {
|
|
131
|
-
return {status: "error", error};
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const simpleRender = () => {
|
|
136
|
-
const input = fs.readFileSync(0);
|
|
137
|
-
const {context, props} = JSON.parse(input.toString("utf8"));
|
|
138
|
-
|
|
139
|
-
process.stdout.write(JSON.stringify(render({context, props})));
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export const serverRender = (body: Buffer) => {
|
|
143
|
-
const {context, props} = JSON.parse(body.toString("utf8"));
|
|
144
|
-
return render({context, props});
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const OK_RESPONSE = 200;
|
|
148
|
-
|
|
149
|
-
const ERROR_REPONSE = 500;
|
|
150
|
-
|
|
151
|
-
// Relative path to keep it under 100 characters.
|
|
152
|
-
// See: https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars
|
|
153
|
-
export const SOCKET_PATH =
|
|
154
|
-
process.env.REACTIVATED_SOCKET ?? `node_modules/_reactivated/reactivated.sock`;
|
|
155
|
-
|
|
156
|
-
export const server = http.createServer((req, res) => {
|
|
157
|
-
let body = Buffer.from("");
|
|
158
|
-
|
|
159
|
-
req.on("data", (chunk) => {
|
|
160
|
-
body = Buffer.concat([body, chunk as Buffer]);
|
|
161
|
-
});
|
|
162
|
-
req.on("end", async () => {
|
|
163
|
-
const result = await serverRender(body);
|
|
164
|
-
|
|
165
|
-
if (result.status === "success") {
|
|
166
|
-
res.writeHead(OK_RESPONSE, {"Content-Type": "text/html; charset=utf-8"});
|
|
167
|
-
res.end(result.rendered);
|
|
168
|
-
} else {
|
|
169
|
-
res.writeHead(ERROR_REPONSE, {"Content-Type": "application/json"});
|
|
170
|
-
res.end(
|
|
171
|
-
JSON.stringify(result.error, Object.getOwnPropertyNames(result.error)),
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
if (fs.existsSync(SOCKET_PATH)) {
|
|
178
|
-
fs.unlinkSync(SOCKET_PATH);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
server.listen(SOCKET_PATH, () => {
|
|
182
|
-
const address = server.address();
|
|
183
|
-
|
|
184
|
-
if (address == null) {
|
|
185
|
-
throw new Error();
|
|
186
|
-
} else if (typeof address === "string") {
|
|
187
|
-
process.stdout.write(`RENDERER:${address}:LISTENING`);
|
|
188
|
-
} else {
|
|
189
|
-
process.stdout.write(`RENDERER:${address.port.toString()}:LISTENING`);
|
|
190
|
-
}
|
|
191
|
-
});
|