@dr.pogodin/react-utils 1.47.0-alpha.2 → 1.47.0-alpha.3
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/babel.config.js +1 -1
- package/babel.module.config.js +11 -0
- package/bin/build.js +8 -4
- package/bin/setup.js +2 -3
- package/build/development/client/getInj.js +9 -18
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +14 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +9 -178
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +25 -50
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +56 -67
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +47 -58
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +9 -16
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +6 -13
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +4 -10
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +11 -18
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -22
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +7 -14
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +15 -22
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +7 -14
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +12 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +16 -23
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +10 -17
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +12 -19
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +20 -28
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +13 -19
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +10 -17
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +8 -16
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +20 -31
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +22 -29
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +13 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +5 -5
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -2
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +21 -19
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -9
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +3 -3
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +14 -14
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -11
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -1
- package/build/types-code/server/index.d.ts +2 -2
- package/build/web/client/getInj.js +2 -2
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/server/index.js +9 -15
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +12 -10
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +2 -4
- package/build/web/server/server.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +1 -2
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/webpack.js +11 -7
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.js +5 -5
- package/config/jest/default.js +1 -0
- package/config/webpack/app-base.js +11 -10
- package/config/webpack/app-development.js +3 -3
- package/config/webpack/lib-base.js +1 -1
- package/package.json +8 -6
- package/src/client/getInj.ts +2 -2
- package/src/server/index.ts +9 -15
- package/src/server/renderer.tsx +11 -10
- package/src/server/server.ts +2 -4
- package/src/shared/utils/jest/E2eSsrEnv.ts +1 -2
- package/src/shared/utils/webpack.ts +14 -8
- package/types.d.ts +1 -1
|
@@ -1,53 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = launchServer;
|
|
8
|
-
Object.defineProperty(exports, "errors", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _utils.errors;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "getDefaultCspSettings", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return _server.getDefaultCspSettings;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
require("source-map-support/register");
|
|
21
|
-
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
22
|
-
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
23
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
24
|
-
var _defaults = _interopRequireDefault(require("lodash/defaults"));
|
|
25
|
-
var _isFinite = _interopRequireDefault(require("lodash/isFinite"));
|
|
26
|
-
var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
|
|
27
|
-
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
28
|
-
var _toNumber = _interopRequireDefault(require("lodash/toNumber"));
|
|
29
|
-
require("raf/polyfill");
|
|
30
|
-
var _server = _interopRequireWildcard(require("./server"));
|
|
31
|
-
var _renderer = require("./renderer");
|
|
32
|
-
var _utils = require("./utils");
|
|
33
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
34
1
|
// eslint-disable-next-line import/no-unassigned-import
|
|
2
|
+
import 'source-map-support/register.js';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import https from 'node:https';
|
|
5
|
+
import { cloneDeep, defaults } from 'lodash-es';
|
|
35
6
|
|
|
36
7
|
// Polyfill required by ReactJS.
|
|
37
8
|
// TODO: Double-check, if it is still required by React v19?
|
|
38
9
|
// eslint-disable-next-line import/no-unassigned-import
|
|
10
|
+
import 'raf/polyfill.js';
|
|
11
|
+
import serverFactory, { getDefaultCspSettings } from "./server.js";
|
|
12
|
+
import { SCRIPT_LOCATIONS, newDefaultLogger } from "./renderer.js";
|
|
13
|
+
import { errors } from "./utils/index.js";
|
|
14
|
+
export { errors, getDefaultCspSettings };
|
|
39
15
|
|
|
40
16
|
/**
|
|
41
17
|
* Normalizes a port into a number, string, or false.
|
|
42
18
|
* TODO: Drop this function?
|
|
43
19
|
* @param value Port name or number.
|
|
44
|
-
* @return Port number (Number), name (String)
|
|
20
|
+
* @return Port number (Number), name (String).
|
|
45
21
|
*/
|
|
46
22
|
function normalizePort(value) {
|
|
47
|
-
const port =
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
return false;
|
|
23
|
+
const port = typeof value === 'string' ? parseInt(value) : value;
|
|
24
|
+
if (Number.isFinite(port)) return port; /* port number */
|
|
25
|
+
return value; /* named pipe */
|
|
51
26
|
}
|
|
52
27
|
/**
|
|
53
28
|
* Creates and launches web-server for ReactJS application. Allows zero
|
|
@@ -167,36 +142,36 @@ function normalizePort(value) {
|
|
|
167
142
|
* defaults to 1 second.
|
|
168
143
|
* @return Resolves to an object with created Express and HTTP servers.
|
|
169
144
|
*/
|
|
170
|
-
async function launchServer(webpackConfig, options = {}) {
|
|
145
|
+
export default async function launchServer(webpackConfig, options = {}) {
|
|
171
146
|
/* Options normalization. */
|
|
172
|
-
const ops = (
|
|
147
|
+
const ops = cloneDeep(options);
|
|
173
148
|
|
|
174
149
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
175
150
|
ops.port = normalizePort(ops.port || process.env.PORT || 3000);
|
|
176
|
-
(
|
|
151
|
+
defaults(ops, {
|
|
177
152
|
httpsRedirect: true
|
|
178
153
|
});
|
|
179
154
|
|
|
180
155
|
// TODO: Need a separate type for normalized options, which guarantees
|
|
181
156
|
// the logger is set!
|
|
182
|
-
ops.logger ??=
|
|
157
|
+
ops.logger ??= newDefaultLogger({
|
|
183
158
|
defaultLogLevel: ops.defaultLoggerLogLevel
|
|
184
159
|
});
|
|
185
160
|
|
|
186
161
|
/* Creates servers, resolves and sets the port. */
|
|
187
|
-
const expressServer = await (
|
|
162
|
+
const expressServer = await serverFactory(webpackConfig, ops);
|
|
188
163
|
let httpServer;
|
|
189
164
|
if (ops.https) {
|
|
190
|
-
httpServer =
|
|
165
|
+
httpServer = https.createServer({
|
|
191
166
|
cert: ops.https.cert,
|
|
192
167
|
key: ops.https.key
|
|
193
168
|
}, expressServer);
|
|
194
|
-
} else httpServer =
|
|
169
|
+
} else httpServer = http.createServer(expressServer);
|
|
195
170
|
|
|
196
171
|
/* Sets error handler for HTTP(S) server. */
|
|
197
172
|
httpServer.on('error', error => {
|
|
198
173
|
if (error.syscall !== 'listen') throw error;
|
|
199
|
-
const bind =
|
|
174
|
+
const bind = typeof ops.port === 'string' ? `Pipe ${ops.port}` : `Port ${ops.port}`;
|
|
200
175
|
|
|
201
176
|
/* Human-readable message for some specific listen errors. */
|
|
202
177
|
switch (error.code) {
|
|
@@ -215,7 +190,7 @@ async function launchServer(webpackConfig, options = {}) {
|
|
|
215
190
|
/* Listening event handler for HTTP(S) server. */
|
|
216
191
|
httpServer.on('listening', () => {
|
|
217
192
|
const addr = httpServer.address();
|
|
218
|
-
const bind =
|
|
193
|
+
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
|
|
219
194
|
ops.logger.info(`Server listening on ${bind} in ${process.env.NODE_ENV} mode`);
|
|
220
195
|
});
|
|
221
196
|
httpServer.listen(ops.port);
|
|
@@ -224,7 +199,7 @@ async function launchServer(webpackConfig, options = {}) {
|
|
|
224
199
|
httpServer
|
|
225
200
|
};
|
|
226
201
|
}
|
|
227
|
-
launchServer.SCRIPT_LOCATIONS =
|
|
228
|
-
launchServer.getDefaultCspSettings =
|
|
229
|
-
launchServer.errors =
|
|
202
|
+
launchServer.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;
|
|
203
|
+
launchServer.getDefaultCspSettings = getDefaultCspSettings;
|
|
204
|
+
launchServer.errors = errors;
|
|
230
205
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["require","_nodeHttp","_interopRequireDefault","_nodeHttps","_cloneDeep","_defaults","_isFinite","_isNumber","_isString","_toNumber","_server","_interopRequireWildcard","_renderer","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","normalizePort","value","port","toNumber","isFinite","isNumber","launchServer","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","logger","newDefaultLogger","defaultLogLevel","defaultLoggerLogLevel","expressServer","serverFactory","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","undefined","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS","getDefaultCspSettings","errors"],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport cloneDeep from 'lodash/cloneDeep';\nimport defaults from 'lodash/defaults';\nimport isFinite from 'lodash/isFinite';\nimport isNumber from 'lodash/isNumber';\nimport isString from 'lodash/isString';\nimport toNumber from 'lodash/toNumber';\n\n// Polyfill required by ReactJS.\n// TODO: Double-check, if it is still required by React v19?\n// eslint-disable-next-line import/no-unassigned-import\nimport 'raf/polyfill';\n\nimport type { Configuration } from 'webpack';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport { errors } from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport { errors, getDefaultCspSettings, type ServerT };\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @param value Port name or number.\n * @return Port number (Number), name (String), or false.\n */\nfunction normalizePort(value: number | string) {\n const port = toNumber(value);\n if (isFinite(port)) return port; /* port number */\n if (!isNumber(port)) return value; /* named pipe */\n return false;\n}\n\ntype OptionsT = ServerOptionsT & {\n https?: {\n cert: string;\n key: string;\n };\n\n // TODO: Should we limit it to number | string, and throw if it is different value?\n port?: false | number | string;\n};\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return Resolves to an object with created Express and HTTP servers.\n */\nexport default async function launchServer(\n webpackConfig: Configuration,\n options: OptionsT = {},\n): Promise<{\n expressServer: ServerT;\n httpServer: http.Server;\n}> {\n /* Options normalization. */\n const ops = cloneDeep(options);\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n // TODO: Need a separate type for normalized options, which guarantees\n // the logger is set!\n ops.logger ??= newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer: http.Server;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer as unknown as () => void);\n } else httpServer = http.createServer(expressServer as unknown as () => void);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error: Error) => {\n if ((error as { syscall?: string }).syscall !== 'listen') throw error;\n const bind = isString(ops.port) ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch ((error as { code?: string }).code) {\n case 'EACCES':\n ops.logger!.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger!.error(`${bind} is already in use`);\n return process.exit(1);\n case undefined:\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address()!;\n const bind = isString(addr) ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger!.info(`Server listening on ${bind} in ${\n process.env.NODE_ENV} mode`);\n });\n\n httpServer.listen(ops.port);\n\n return {\n expressServer,\n httpServer,\n };\n}\n\nlaunchServer.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;\nlaunchServer.getDefaultCspSettings = getDefaultCspSettings;\nlaunchServer.errors = errors;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACAA,OAAA;AAEA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,UAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAAI,UAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,SAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,SAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,SAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,SAAA,GAAAP,sBAAA,CAAAF,OAAA;AAKAA,OAAA;AAIA,IAAAU,OAAA,GAAAC,uBAAA,CAAAX,OAAA;AAMA,IAAAY,SAAA,GAAAZ,OAAA;AAEA,IAAAa,MAAA,GAAAb,OAAA;AAAe,SAAAW,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AA5Bf;;AAaA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA,SAASkB,aAAaA,CAACC,KAAsB,EAAE;EAC7C,MAAMC,IAAI,GAAG,IAAAC,iBAAQ,EAACF,KAAK,CAAC;EAC5B,IAAI,IAAAG,iBAAQ,EAACF,IAAI,CAAC,EAAE,OAAOA,IAAI,CAAC,CAAC;EACjC,IAAI,CAAC,IAAAG,iBAAQ,EAACH,IAAI,CAAC,EAAE,OAAOD,KAAK,CAAC,CAAC;EACnC,OAAO,KAAK;AACd;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,eAAeK,YAAYA,CACxCC,aAA4B,EAC5BC,OAAiB,GAAG,CAAC,CAAC,EAIrB;EACD;EACA,MAAMC,GAAG,GAAG,IAAAC,kBAAS,EAACF,OAAO,CAAC;;EAE9B;EACAC,GAAG,CAACP,IAAI,GAAGF,aAAa,CAACS,GAAG,CAACP,IAAI,IAAIS,OAAO,CAACC,GAAG,CAACC,IAAI,IAAI,IAAI,CAAC;EAC9D,IAAAC,iBAAQ,EAACL,GAAG,EAAE;IAAEM,aAAa,EAAE;EAAK,CAAC,CAAC;;EAEtC;EACA;EACAN,GAAG,CAACO,MAAM,KAAK,IAAAC,0BAAgB,EAAC;IAC9BC,eAAe,EAAET,GAAG,CAACU;EACvB,CAAC,CAAC;;EAEF;EACA,MAAMC,aAAa,GAAG,MAAM,IAAAC,eAAa,EAACd,aAAa,EAAEE,GAAG,CAAC;EAE7D,IAAIa,UAAuB;EAC3B,IAAIb,GAAG,CAACc,KAAK,EAAE;IACbD,UAAU,GAAGC,kBAAK,CAACC,YAAY,CAAC;MAC9BC,IAAI,EAAEhB,GAAG,CAACc,KAAK,CAACE,IAAI;MACpBC,GAAG,EAAEjB,GAAG,CAACc,KAAK,CAACG;IACjB,CAAC,EAAEN,aAAsC,CAAC;EAC5C,CAAC,MAAME,UAAU,GAAGK,iBAAI,CAACH,YAAY,CAACJ,aAAsC,CAAC;;EAE7E;EACAE,UAAU,CAACM,EAAE,CAAC,OAAO,EAAGC,KAAY,IAAK;IACvC,IAAKA,KAAK,CAA0BC,OAAO,KAAK,QAAQ,EAAE,MAAMD,KAAK;IACrE,MAAME,IAAI,GAAG,IAAAC,iBAAQ,EAACvB,GAAG,CAACP,IAAI,CAAC,GAAG,QAAQO,GAAG,CAACP,IAAI,EAAE,GAAG,QAAQO,GAAG,CAACP,IAAI,EAAE;;IAEzE;IACA,QAAS2B,KAAK,CAAuBI,IAAI;MACvC,KAAK,QAAQ;QACXxB,GAAG,CAACO,MAAM,CAAEa,KAAK,CAAC,GAAGE,IAAI,+BAA+B,CAAC;QACzD,OAAOpB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAK,YAAY;QACfzB,GAAG,CAACO,MAAM,CAAEa,KAAK,CAAC,GAAGE,IAAI,oBAAoB,CAAC;QAC9C,OAAOpB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAKC,SAAS;MACd;QACE,MAAMN,KAAK;IACf;EACF,CAAC,CAAC;;EAEF;EACAP,UAAU,CAACM,EAAE,CAAC,WAAW,EAAE,MAAM;IAC/B,MAAMQ,IAAI,GAAGd,UAAU,CAACe,OAAO,CAAC,CAAE;IAClC,MAAMN,IAAI,GAAG,IAAAC,iBAAQ,EAACI,IAAI,CAAC,GAAG,QAAQA,IAAI,EAAE,GAAG,QAAQA,IAAI,CAAClC,IAAI,EAAE;IAClEO,GAAG,CAACO,MAAM,CAAEsB,IAAI,CAAC,uBAAuBP,IAAI,OAC1CpB,OAAO,CAACC,GAAG,CAAC2B,QAAQ,OAAO,CAAC;EAChC,CAAC,CAAC;EAEFjB,UAAU,CAACkB,MAAM,CAAC/B,GAAG,CAACP,IAAI,CAAC;EAE3B,OAAO;IACLkB,aAAa;IACbE;EACF,CAAC;AACH;AAEAhB,YAAY,CAACmC,gBAAgB,GAAGA,0BAAgB;AAChDnC,YAAY,CAACoC,qBAAqB,GAAGA,6BAAqB;AAC1DpC,YAAY,CAACqC,MAAM,GAAGA,aAAM","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["http","https","cloneDeep","defaults","serverFactory","getDefaultCspSettings","SCRIPT_LOCATIONS","newDefaultLogger","errors","normalizePort","value","port","parseInt","Number","isFinite","launchServer","webpackConfig","options","ops","process","env","PORT","httpsRedirect","logger","defaultLogLevel","defaultLoggerLogLevel","expressServer","httpServer","createServer","cert","key","on","error","syscall","bind","code","exit","undefined","addr","address","info","NODE_ENV","listen"],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register.js';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport { cloneDeep, defaults } from 'lodash-es';\n\n// Polyfill required by ReactJS.\n// TODO: Double-check, if it is still required by React v19?\n// eslint-disable-next-line import/no-unassigned-import\nimport 'raf/polyfill.js';\n\nimport type { Configuration } from 'webpack';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport { errors } from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport { errors, getDefaultCspSettings, type ServerT };\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @param value Port name or number.\n * @return Port number (Number), name (String).\n */\nfunction normalizePort(value: number | string) {\n const port = typeof value === 'string' ? parseInt(value) : value;\n if (Number.isFinite(port)) return port; /* port number */\n return value; /* named pipe */\n}\n\ntype OptionsT = ServerOptionsT & {\n https?: {\n cert: string;\n key: string;\n };\n\n // TODO: Should we limit it to number | string, and throw if it is different value?\n port?: false | number | string;\n};\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return Resolves to an object with created Express and HTTP servers.\n */\nexport default async function launchServer(\n webpackConfig: Configuration,\n options: OptionsT = {},\n): Promise<{\n expressServer: ServerT;\n httpServer: http.Server;\n}> {\n /* Options normalization. */\n const ops = cloneDeep(options);\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n // TODO: Need a separate type for normalized options, which guarantees\n // the logger is set!\n ops.logger ??= newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer: http.Server;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer as unknown as () => void);\n } else httpServer = http.createServer(expressServer as unknown as () => void);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error: Error) => {\n if ((error as { syscall?: string }).syscall !== 'listen') throw error;\n const bind = typeof ops.port === 'string' ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch ((error as { code?: string }).code) {\n case 'EACCES':\n ops.logger!.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger!.error(`${bind} is already in use`);\n return process.exit(1);\n case undefined:\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address()!;\n const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger!.info(`Server listening on ${bind} in ${\n process.env.NODE_ENV} mode`);\n });\n\n httpServer.listen(ops.port);\n\n return {\n expressServer,\n httpServer,\n };\n}\n\nlaunchServer.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;\nlaunchServer.getDefaultCspSettings = getDefaultCspSettings;\nlaunchServer.errors = errors;\n"],"mappings":"AAAA;AACA,OAAO,gCAAgC;AAEvC,OAAOA,IAAI,MAAM,WAAW;AAC5B,OAAOC,KAAK,MAAM,YAAY;AAE9B,SAASC,SAAS,EAAEC,QAAQ,QAAQ,WAAW;;AAE/C;AACA;AACA;AACA,OAAO,iBAAiB;AAAA,OAIjBC,aAAa,IAGlBC,qBAAqB;AAAA,SAGdC,gBAAgB,EAAEC,gBAAgB;AAAA,SAElCC,MAAM;AASf,SAASA,MAAM,EAAEH,qBAAqB;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,aAAaA,CAACC,KAAsB,EAAE;EAC7C,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGE,QAAQ,CAACF,KAAK,CAAC,GAAGA,KAAK;EAChE,IAAIG,MAAM,CAACC,QAAQ,CAACH,IAAI,CAAC,EAAE,OAAOA,IAAI,CAAC,CAAC;EACxC,OAAOD,KAAK,CAAC,CAAC;AAChB;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,eAAeK,YAAYA,CACxCC,aAA4B,EAC5BC,OAAiB,GAAG,CAAC,CAAC,EAIrB;EACD;EACA,MAAMC,GAAG,GAAGhB,SAAS,CAACe,OAAO,CAAC;;EAE9B;EACAC,GAAG,CAACP,IAAI,GAAGF,aAAa,CAACS,GAAG,CAACP,IAAI,IAAIQ,OAAO,CAACC,GAAG,CAACC,IAAI,IAAI,IAAI,CAAC;EAC9DlB,QAAQ,CAACe,GAAG,EAAE;IAAEI,aAAa,EAAE;EAAK,CAAC,CAAC;;EAEtC;EACA;EACAJ,GAAG,CAACK,MAAM,KAAKhB,gBAAgB,CAAC;IAC9BiB,eAAe,EAAEN,GAAG,CAACO;EACvB,CAAC,CAAC;;EAEF;EACA,MAAMC,aAAa,GAAG,MAAMtB,aAAa,CAACY,aAAa,EAAEE,GAAG,CAAC;EAE7D,IAAIS,UAAuB;EAC3B,IAAIT,GAAG,CAACjB,KAAK,EAAE;IACb0B,UAAU,GAAG1B,KAAK,CAAC2B,YAAY,CAAC;MAC9BC,IAAI,EAAEX,GAAG,CAACjB,KAAK,CAAC4B,IAAI;MACpBC,GAAG,EAAEZ,GAAG,CAACjB,KAAK,CAAC6B;IACjB,CAAC,EAAEJ,aAAsC,CAAC;EAC5C,CAAC,MAAMC,UAAU,GAAG3B,IAAI,CAAC4B,YAAY,CAACF,aAAsC,CAAC;;EAE7E;EACAC,UAAU,CAACI,EAAE,CAAC,OAAO,EAAGC,KAAY,IAAK;IACvC,IAAKA,KAAK,CAA0BC,OAAO,KAAK,QAAQ,EAAE,MAAMD,KAAK;IACrE,MAAME,IAAI,GAAG,OAAOhB,GAAG,CAACP,IAAI,KAAK,QAAQ,GAAG,QAAQO,GAAG,CAACP,IAAI,EAAE,GAAG,QAAQO,GAAG,CAACP,IAAI,EAAE;;IAEnF;IACA,QAASqB,KAAK,CAAuBG,IAAI;MACvC,KAAK,QAAQ;QACXjB,GAAG,CAACK,MAAM,CAAES,KAAK,CAAC,GAAGE,IAAI,+BAA+B,CAAC;QACzD,OAAOf,OAAO,CAACiB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAK,YAAY;QACflB,GAAG,CAACK,MAAM,CAAES,KAAK,CAAC,GAAGE,IAAI,oBAAoB,CAAC;QAC9C,OAAOf,OAAO,CAACiB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAKC,SAAS;MACd;QACE,MAAML,KAAK;IACf;EACF,CAAC,CAAC;;EAEF;EACAL,UAAU,CAACI,EAAE,CAAC,WAAW,EAAE,MAAM;IAC/B,MAAMO,IAAI,GAAGX,UAAU,CAACY,OAAO,CAAC,CAAE;IAClC,MAAML,IAAI,GAAG,OAAOI,IAAI,KAAK,QAAQ,GAAG,QAAQA,IAAI,EAAE,GAAG,QAAQA,IAAI,CAAC3B,IAAI,EAAE;IAC5EO,GAAG,CAACK,MAAM,CAAEiB,IAAI,CAAC,uBAAuBN,IAAI,OAC1Cf,OAAO,CAACC,GAAG,CAACqB,QAAQ,OAAO,CAAC;EAChC,CAAC,CAAC;EAEFd,UAAU,CAACe,MAAM,CAACxB,GAAG,CAACP,IAAI,CAAC;EAE3B,OAAO;IACLe,aAAa;IACbC;EACF,CAAC;AACH;AAEAZ,YAAY,CAACT,gBAAgB,GAAGA,gBAAgB;AAChDS,YAAY,CAACV,qBAAqB,GAAGA,qBAAqB;AAC1DU,YAAY,CAACP,MAAM,GAAGA,MAAM","ignoreList":[]}
|
|
@@ -1,41 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ServerSsrContext = exports.SCRIPT_LOCATIONS = void 0;
|
|
8
|
-
exports.default = factory;
|
|
9
|
-
exports.isBrotliAcceptable = isBrotliAcceptable;
|
|
10
|
-
exports.newDefaultLogger = newDefaultLogger;
|
|
11
|
-
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
12
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
13
|
-
var _nodeStream = require("node:stream");
|
|
14
|
-
var _nodeZlib = require("node:zlib");
|
|
15
|
-
var _winston = _interopRequireDefault(require("winston"));
|
|
16
|
-
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
17
|
-
var _jsUtils = require("@dr.pogodin/js-utils");
|
|
18
|
-
var _clone = _interopRequireDefault(require("lodash/clone"));
|
|
19
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
20
|
-
var _defaults = _interopRequireDefault(require("lodash/defaults"));
|
|
21
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
22
|
-
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
23
|
-
var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
|
|
24
|
-
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
25
|
-
var _config = _interopRequireDefault(require("config"));
|
|
26
|
-
var _nodeForge = _interopRequireDefault(require("node-forge"));
|
|
27
|
-
var _static = require("react-dom/static");
|
|
28
|
-
var _reactHelmet = require("@dr.pogodin/react-helmet");
|
|
29
|
-
var _reactRouter = require("react-router");
|
|
30
|
-
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
|
|
31
|
-
var _buildInfo = require("../shared/utils/isomorphy/buildInfo");
|
|
32
|
-
var _Cache = _interopRequireDefault(require("./Cache"));
|
|
33
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
34
1
|
/**
|
|
35
2
|
* ExpressJS middleware for server-side rendering of a ReactJS app.
|
|
36
3
|
*/
|
|
37
4
|
|
|
38
|
-
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { Writable } from 'node:stream';
|
|
8
|
+
import { brotliCompress, brotliDecompress } from 'node:zlib';
|
|
9
|
+
import winston from 'winston';
|
|
10
|
+
import { GlobalStateProvider, SsrContext } from '@dr.pogodin/react-global-state';
|
|
11
|
+
import { timer } from '@dr.pogodin/js-utils';
|
|
12
|
+
import { cloneDeep, defaults, get, mapValues } from 'lodash-es';
|
|
13
|
+
import config from 'config';
|
|
14
|
+
import forge from 'node-forge';
|
|
15
|
+
import { prerenderToNodeStream } from 'react-dom/static';
|
|
16
|
+
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
17
|
+
import { StaticRouter } from 'react-router';
|
|
18
|
+
import serializeJs from 'serialize-javascript';
|
|
19
|
+
import { setBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
|
|
20
|
+
import Cache from "./Cache.js"; // @ts-expect-error "Property 'SECRET' does not exist on type 'IConfig'."
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
const {
|
|
24
|
+
SECRET,
|
|
25
|
+
...sanitizedConfig
|
|
26
|
+
} = config;
|
|
39
27
|
|
|
40
28
|
// Note: These type definitions for logger are copied from Winston logger,
|
|
41
29
|
// then simplified to make it easier to fit an alternative logger into this
|
|
@@ -46,17 +34,17 @@ const sanitizedConfig = (0, _omit.default)(_config.default, 'SECRET');
|
|
|
46
34
|
|
|
47
35
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
48
36
|
|
|
49
|
-
let SCRIPT_LOCATIONS =
|
|
37
|
+
export let SCRIPT_LOCATIONS = /*#__PURE__*/function (SCRIPT_LOCATIONS) {
|
|
50
38
|
SCRIPT_LOCATIONS["BODY_OPEN"] = "BODY_OPEN";
|
|
51
39
|
SCRIPT_LOCATIONS["DEFAULT"] = "DEFAULT";
|
|
52
40
|
SCRIPT_LOCATIONS["HEAD_OPEN"] = "HEAD_OPEN";
|
|
53
41
|
return SCRIPT_LOCATIONS;
|
|
54
42
|
}({});
|
|
55
|
-
class ServerSsrContext extends
|
|
43
|
+
export class ServerSsrContext extends SsrContext {
|
|
56
44
|
chunks = [];
|
|
57
45
|
status = 200;
|
|
58
46
|
constructor(req, chunkGroups, initialState) {
|
|
59
|
-
super((
|
|
47
|
+
super(cloneDeep(initialState) ?? {});
|
|
60
48
|
this.chunkGroups = chunkGroups;
|
|
61
49
|
this.req = req;
|
|
62
50
|
}
|
|
@@ -70,10 +58,9 @@ class ServerSsrContext extends _reactGlobalState.SsrContext {
|
|
|
70
58
|
* @param context Webpack context path used during the build.
|
|
71
59
|
* @return Resolves to the build-time information.
|
|
72
60
|
*/
|
|
73
|
-
exports.ServerSsrContext = ServerSsrContext;
|
|
74
61
|
function getBuildInfo(context) {
|
|
75
|
-
const url =
|
|
76
|
-
return JSON.parse(
|
|
62
|
+
const url = path.resolve(context, '.build-info');
|
|
63
|
+
return JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
/**
|
|
@@ -85,10 +72,10 @@ function getBuildInfo(context) {
|
|
|
85
72
|
* @return
|
|
86
73
|
*/
|
|
87
74
|
function readChunkGroupsJson(buildDir) {
|
|
88
|
-
const url =
|
|
75
|
+
const url = path.resolve(buildDir, '__chunk_groups__.json');
|
|
89
76
|
let res;
|
|
90
77
|
try {
|
|
91
|
-
res = JSON.parse(
|
|
78
|
+
res = JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
92
79
|
} catch {
|
|
93
80
|
// TODO: Should we message the error here somehow?
|
|
94
81
|
res = null;
|
|
@@ -106,9 +93,9 @@ function readChunkGroupsJson(buildDir) {
|
|
|
106
93
|
*/
|
|
107
94
|
async function prepareCipher(key) {
|
|
108
95
|
return new Promise((resolve, reject) => {
|
|
109
|
-
|
|
96
|
+
forge.random.getBytes(32, (err, iv) => {
|
|
110
97
|
if (err) reject(err);else {
|
|
111
|
-
const cipher =
|
|
98
|
+
const cipher = forge.cipher.createCipher('AES-CBC', key);
|
|
112
99
|
cipher.start({
|
|
113
100
|
iv
|
|
114
101
|
});
|
|
@@ -126,7 +113,7 @@ async function prepareCipher(key) {
|
|
|
126
113
|
* are acceptable to the caller.
|
|
127
114
|
* @param req
|
|
128
115
|
*/
|
|
129
|
-
function isBrotliAcceptable(req) {
|
|
116
|
+
export function isBrotliAcceptable(req) {
|
|
130
117
|
const acceptable = req.get('accept-encoding');
|
|
131
118
|
if (acceptable) {
|
|
132
119
|
const ops = acceptable.split(',');
|
|
@@ -161,7 +148,7 @@ function groupExtraScripts(scripts = []) {
|
|
|
161
148
|
[SCRIPT_LOCATIONS.HEAD_OPEN]: ''
|
|
162
149
|
};
|
|
163
150
|
for (const script of scripts) {
|
|
164
|
-
if (
|
|
151
|
+
if (typeof script === 'string') {
|
|
165
152
|
if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;
|
|
166
153
|
} else if (script.code) {
|
|
167
154
|
if (script.location in res) res[script.location] += script.code;else throw Error(`Invalid location "${script.location}"`);
|
|
@@ -176,14 +163,14 @@ function groupExtraScripts(scripts = []) {
|
|
|
176
163
|
* @param {string} [options.defaultLogLevel='info']
|
|
177
164
|
* @return {object}
|
|
178
165
|
*/
|
|
179
|
-
function newDefaultLogger({
|
|
166
|
+
export function newDefaultLogger({
|
|
180
167
|
defaultLogLevel = 'info'
|
|
181
168
|
} = {}) {
|
|
182
169
|
const {
|
|
183
170
|
format,
|
|
184
171
|
transports
|
|
185
|
-
} =
|
|
186
|
-
return
|
|
172
|
+
} = winston;
|
|
173
|
+
return winston.createLogger({
|
|
187
174
|
format: format.combine(format.splat(), format.timestamp(), format.colorize(), format.printf(({
|
|
188
175
|
level,
|
|
189
176
|
message,
|
|
@@ -233,8 +220,10 @@ function newDefaultLogger({
|
|
|
233
220
|
* If undefined - infinite age is assumed.
|
|
234
221
|
* @return Created middleware.
|
|
235
222
|
*/
|
|
236
|
-
function factory(webpackConfig, options) {
|
|
237
|
-
const ops = (
|
|
223
|
+
export default function factory(webpackConfig, options) {
|
|
224
|
+
const ops = defaults({
|
|
225
|
+
...options
|
|
226
|
+
}, {
|
|
238
227
|
beforeRender: async () => Promise.resolve({}),
|
|
239
228
|
maxSsrRounds: 10,
|
|
240
229
|
ssrTimeout: 1000,
|
|
@@ -248,18 +237,18 @@ function factory(webpackConfig, options) {
|
|
|
248
237
|
defaultLogLevel: ops.defaultLoggerLogLevel
|
|
249
238
|
});
|
|
250
239
|
const buildInfo = ops.buildInfo ?? getBuildInfo(webpackConfig.context);
|
|
251
|
-
|
|
240
|
+
setBuildInfo(buildInfo);
|
|
252
241
|
|
|
253
242
|
// publicPath from webpack.output has a trailing slash at the end.
|
|
254
243
|
const {
|
|
255
244
|
publicPath,
|
|
256
245
|
path: outputPath
|
|
257
246
|
} = webpackConfig.output;
|
|
258
|
-
const manifestLink =
|
|
247
|
+
const manifestLink = fs.existsSync(`${outputPath}/manifest.json`) ? `<link rel="manifest" href="${publicPath}manifest.json">` : '';
|
|
259
248
|
|
|
260
249
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
261
250
|
|
|
262
|
-
const cache = ops.staticCacheController ? new
|
|
251
|
+
const cache = ops.staticCacheController ? new Cache(ops.staticCacheSize) : null;
|
|
263
252
|
const CHUNK_GROUPS = readChunkGroupsJson(outputPath);
|
|
264
253
|
|
|
265
254
|
// TODO: Look at it later.
|
|
@@ -286,7 +275,7 @@ function factory(webpackConfig, options) {
|
|
|
286
275
|
res.send(buffer);
|
|
287
276
|
} else {
|
|
288
277
|
await new Promise((done, failed) => {
|
|
289
|
-
|
|
278
|
+
brotliDecompress(buffer, (error, html) => {
|
|
290
279
|
if (error) failed(error);else {
|
|
291
280
|
let h = html.toString();
|
|
292
281
|
if (!ops.noCsp) {
|
|
@@ -328,9 +317,9 @@ function factory(webpackConfig, options) {
|
|
|
328
317
|
// attached to the request (in dev mode), or from a file output during
|
|
329
318
|
// the build (in prod mode).
|
|
330
319
|
let chunkGroups;
|
|
331
|
-
const webpackStats = (
|
|
320
|
+
const webpackStats = get(res.locals, 'webpack.devMiddleware.stats');
|
|
332
321
|
if (webpackStats) {
|
|
333
|
-
chunkGroups = (
|
|
322
|
+
chunkGroups = mapValues(webpackStats.toJson({
|
|
334
323
|
all: false,
|
|
335
324
|
chunkGroups: true
|
|
336
325
|
}).namedChunkGroups, item => item.assets?.map(({
|
|
@@ -375,14 +364,14 @@ function factory(webpackConfig, options) {
|
|
|
375
364
|
// TODO: prerenderToNodeStream has (abort) "signal" option,
|
|
376
365
|
// and we should wire it up to the SSR timeout below.
|
|
377
366
|
const helmetContext = {};
|
|
378
|
-
void
|
|
367
|
+
void prerenderToNodeStream(/*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
379
368
|
initialState: ssrContext.state,
|
|
380
369
|
ssrContext: ssrContext,
|
|
381
|
-
children: /*#__PURE__*/(
|
|
370
|
+
children: /*#__PURE__*/_jsx(StaticRouter, {
|
|
382
371
|
location: req.url,
|
|
383
|
-
children: /*#__PURE__*/(
|
|
372
|
+
children: /*#__PURE__*/_jsx(HelmetProvider, {
|
|
384
373
|
context: helmetContext,
|
|
385
|
-
children: /*#__PURE__*/(
|
|
374
|
+
children: /*#__PURE__*/_jsx(App2, {})
|
|
386
375
|
})
|
|
387
376
|
})
|
|
388
377
|
}), {
|
|
@@ -400,7 +389,7 @@ function factory(webpackConfig, options) {
|
|
|
400
389
|
stream = await renderPass();
|
|
401
390
|
if (!ssrContext.dirty) break;
|
|
402
391
|
const timeout = ops.ssrTimeout + ssrStart - Date.now();
|
|
403
|
-
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending),
|
|
392
|
+
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending), timer(timeout).then(() => false)]));
|
|
404
393
|
if (bailed) break;
|
|
405
394
|
}
|
|
406
395
|
let logMsg;
|
|
@@ -417,7 +406,7 @@ function factory(webpackConfig, options) {
|
|
|
417
406
|
return;
|
|
418
407
|
}
|
|
419
408
|
await new Promise(ready => {
|
|
420
|
-
stream.pipe(new
|
|
409
|
+
stream.pipe(new Writable({
|
|
421
410
|
destroy: ready,
|
|
422
411
|
write: (chunk, _, done) => {
|
|
423
412
|
appHtmlMarkup += chunk.toString();
|
|
@@ -432,7 +421,7 @@ function factory(webpackConfig, options) {
|
|
|
432
421
|
* contains decryption key and is able to decode it at the client side.
|
|
433
422
|
* Hovewer, for a number of reasons, encryption of injected data is still
|
|
434
423
|
* better than injection of a plain text. */
|
|
435
|
-
const payload = (
|
|
424
|
+
const payload = serializeJs({
|
|
436
425
|
CHUNK_GROUPS: chunkGroups,
|
|
437
426
|
CONFIG: configToInject ?? sanitizedConfig,
|
|
438
427
|
ISTATE: ssrContext.state
|
|
@@ -440,9 +429,9 @@ function factory(webpackConfig, options) {
|
|
|
440
429
|
ignoreFunction: true,
|
|
441
430
|
unsafe: true
|
|
442
431
|
});
|
|
443
|
-
cipher.update(
|
|
432
|
+
cipher.update(forge.util.createBuffer(payload, 'utf8'));
|
|
444
433
|
cipher.finish();
|
|
445
|
-
const INJ =
|
|
434
|
+
const INJ = forge.util.encode64(`${iv}${cipher.output.data}`);
|
|
446
435
|
const chunkSet = new Set();
|
|
447
436
|
|
|
448
437
|
// TODO: "main" chunk has to be added explicitly,
|
|
@@ -501,7 +490,7 @@ function factory(webpackConfig, options) {
|
|
|
501
490
|
// Note: waiting for the caching to complete is not strictly necessary,
|
|
502
491
|
// but it greately simplifies testing, and error reporting.
|
|
503
492
|
await new Promise((done, failed) => {
|
|
504
|
-
|
|
493
|
+
brotliCompress(html, (error, buffer) => {
|
|
505
494
|
if (error) failed(error);else {
|
|
506
495
|
const b = buffer;
|
|
507
496
|
b.nonce = req.nonce;
|