@dr.pogodin/react-utils 1.47.0-alpha.2 → 1.47.0-alpha.4
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 +47 -45
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +15 -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 +10 -179
- 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 +63 -92
- 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 +40 -20
- 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 +24 -30
- 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 +13 -11
- 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 +3 -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 +24 -25
- 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 +8 -4
- 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 -2
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +1 -1
- package/build/types-code/server/index.d.ts +2 -2
- package/build/types-code/shared/utils/config.d.ts +4 -2
- package/build/types-code/shared/utils/index.d.ts +2 -2
- package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
- package/build/web/client/getInj.js +48 -37
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +3 -2
- package/build/web/client/index.js.map +1 -1
- package/build/web/index.js +3 -3
- package/build/web/index.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 +24 -40
- 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/components/Modal/index.js +2 -2
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/utils/config.js +36 -10
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/index.js +2 -2
- package/build/web/shared/utils/index.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/splitComponent.js +2 -1
- package/build/web/shared/utils/splitComponent.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/jest/setup.js +8 -1
- package/config/webpack/app-base.js +13 -12
- package/config/webpack/app-development.js +3 -3
- package/config/webpack/lib-base.js +1 -2
- package/package.json +9 -9
- package/src/client/getInj.ts +60 -40
- package/src/client/index.tsx +5 -3
- package/src/index.ts +3 -3
- package/src/server/index.ts +9 -15
- package/src/server/renderer.tsx +27 -45
- package/src/server/server.ts +2 -4
- package/src/shared/components/Modal/index.tsx +2 -2
- package/src/shared/utils/config.ts +48 -12
- package/src/shared/utils/index.ts +2 -2
- package/src/shared/utils/jest/E2eSsrEnv.ts +1 -2
- package/src/shared/utils/splitComponent.tsx +14 -2
- package/src/shared/utils/webpack.ts +14 -8
- package/types.d.ts +1 -6
|
@@ -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,30 @@
|
|
|
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 { Buffer } from 'node:buffer';
|
|
6
|
+
import { createCipheriv, randomBytes } from 'node:crypto';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { Writable } from 'node:stream';
|
|
10
|
+
import { brotliCompress, brotliDecompress } from 'node:zlib';
|
|
11
|
+
import winston from 'winston';
|
|
12
|
+
import { GlobalStateProvider, SsrContext } from '@dr.pogodin/react-global-state';
|
|
13
|
+
import { timer } from '@dr.pogodin/js-utils';
|
|
14
|
+
import { cloneDeep, defaults, get, mapValues } from 'lodash-es';
|
|
15
|
+
import config from 'config';
|
|
16
|
+
import { prerenderToNodeStream } from 'react-dom/static';
|
|
17
|
+
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
18
|
+
import { StaticRouter } from 'react-router';
|
|
19
|
+
import serializeJs from 'serialize-javascript';
|
|
20
|
+
import { setBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
|
|
21
|
+
import Cache from "./Cache.js"; // @ts-expect-error "Property 'SECRET' does not exist on type 'IConfig'."
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
const {
|
|
25
|
+
SECRET,
|
|
26
|
+
...sanitizedConfig
|
|
27
|
+
} = config;
|
|
39
28
|
|
|
40
29
|
// Note: These type definitions for logger are copied from Winston logger,
|
|
41
30
|
// then simplified to make it easier to fit an alternative logger into this
|
|
@@ -46,17 +35,17 @@ const sanitizedConfig = (0, _omit.default)(_config.default, 'SECRET');
|
|
|
46
35
|
|
|
47
36
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
48
37
|
|
|
49
|
-
let SCRIPT_LOCATIONS =
|
|
38
|
+
export let SCRIPT_LOCATIONS = /*#__PURE__*/function (SCRIPT_LOCATIONS) {
|
|
50
39
|
SCRIPT_LOCATIONS["BODY_OPEN"] = "BODY_OPEN";
|
|
51
40
|
SCRIPT_LOCATIONS["DEFAULT"] = "DEFAULT";
|
|
52
41
|
SCRIPT_LOCATIONS["HEAD_OPEN"] = "HEAD_OPEN";
|
|
53
42
|
return SCRIPT_LOCATIONS;
|
|
54
43
|
}({});
|
|
55
|
-
class ServerSsrContext extends
|
|
44
|
+
export class ServerSsrContext extends SsrContext {
|
|
56
45
|
chunks = [];
|
|
57
46
|
status = 200;
|
|
58
47
|
constructor(req, chunkGroups, initialState) {
|
|
59
|
-
super((
|
|
48
|
+
super(cloneDeep(initialState) ?? {});
|
|
60
49
|
this.chunkGroups = chunkGroups;
|
|
61
50
|
this.req = req;
|
|
62
51
|
}
|
|
@@ -70,10 +59,9 @@ class ServerSsrContext extends _reactGlobalState.SsrContext {
|
|
|
70
59
|
* @param context Webpack context path used during the build.
|
|
71
60
|
* @return Resolves to the build-time information.
|
|
72
61
|
*/
|
|
73
|
-
exports.ServerSsrContext = ServerSsrContext;
|
|
74
62
|
function getBuildInfo(context) {
|
|
75
|
-
const url =
|
|
76
|
-
return JSON.parse(
|
|
63
|
+
const url = path.resolve(context, '.build-info');
|
|
64
|
+
return JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
77
65
|
}
|
|
78
66
|
|
|
79
67
|
/**
|
|
@@ -85,10 +73,10 @@ function getBuildInfo(context) {
|
|
|
85
73
|
* @return
|
|
86
74
|
*/
|
|
87
75
|
function readChunkGroupsJson(buildDir) {
|
|
88
|
-
const url =
|
|
76
|
+
const url = path.resolve(buildDir, '__chunk_groups__.json');
|
|
89
77
|
let res;
|
|
90
78
|
try {
|
|
91
|
-
res = JSON.parse(
|
|
79
|
+
res = JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
92
80
|
} catch {
|
|
93
81
|
// TODO: Should we message the error here somehow?
|
|
94
82
|
res = null;
|
|
@@ -98,27 +86,15 @@ function readChunkGroupsJson(buildDir) {
|
|
|
98
86
|
|
|
99
87
|
/**
|
|
100
88
|
* Prepares a new Cipher for data encryption.
|
|
101
|
-
* @param key Encryption key (32-bit random key is expected
|
|
102
|
-
*
|
|
103
|
-
* @return Resolves to the object with two fields:
|
|
89
|
+
* @param key Encryption key (32-bit random, Base64-encoded key is expected).
|
|
90
|
+
* @return Returns a tuple of:
|
|
104
91
|
* 1. cipher - a new Cipher, ready for encryption;
|
|
105
92
|
* 2. iv - initial vector used by the cipher.
|
|
106
93
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const cipher = _nodeForge.default.cipher.createCipher('AES-CBC', key);
|
|
112
|
-
cipher.start({
|
|
113
|
-
iv
|
|
114
|
-
});
|
|
115
|
-
resolve({
|
|
116
|
-
cipher,
|
|
117
|
-
iv
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
94
|
+
function prepareCipher(key) {
|
|
95
|
+
const iv = randomBytes(16);
|
|
96
|
+
const cipher = createCipheriv('AES-256-CBC', Buffer.from(key, 'base64'), iv);
|
|
97
|
+
return [cipher, iv];
|
|
122
98
|
}
|
|
123
99
|
|
|
124
100
|
/**
|
|
@@ -126,7 +102,7 @@ async function prepareCipher(key) {
|
|
|
126
102
|
* are acceptable to the caller.
|
|
127
103
|
* @param req
|
|
128
104
|
*/
|
|
129
|
-
function isBrotliAcceptable(req) {
|
|
105
|
+
export function isBrotliAcceptable(req) {
|
|
130
106
|
const acceptable = req.get('accept-encoding');
|
|
131
107
|
if (acceptable) {
|
|
132
108
|
const ops = acceptable.split(',');
|
|
@@ -161,7 +137,7 @@ function groupExtraScripts(scripts = []) {
|
|
|
161
137
|
[SCRIPT_LOCATIONS.HEAD_OPEN]: ''
|
|
162
138
|
};
|
|
163
139
|
for (const script of scripts) {
|
|
164
|
-
if (
|
|
140
|
+
if (typeof script === 'string') {
|
|
165
141
|
if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;
|
|
166
142
|
} else if (script.code) {
|
|
167
143
|
if (script.location in res) res[script.location] += script.code;else throw Error(`Invalid location "${script.location}"`);
|
|
@@ -176,14 +152,14 @@ function groupExtraScripts(scripts = []) {
|
|
|
176
152
|
* @param {string} [options.defaultLogLevel='info']
|
|
177
153
|
* @return {object}
|
|
178
154
|
*/
|
|
179
|
-
function newDefaultLogger({
|
|
155
|
+
export function newDefaultLogger({
|
|
180
156
|
defaultLogLevel = 'info'
|
|
181
157
|
} = {}) {
|
|
182
158
|
const {
|
|
183
159
|
format,
|
|
184
160
|
transports
|
|
185
|
-
} =
|
|
186
|
-
return
|
|
161
|
+
} = winston;
|
|
162
|
+
return winston.createLogger({
|
|
187
163
|
format: format.combine(format.splat(), format.timestamp(), format.colorize(), format.printf(({
|
|
188
164
|
level,
|
|
189
165
|
message,
|
|
@@ -233,8 +209,10 @@ function newDefaultLogger({
|
|
|
233
209
|
* If undefined - infinite age is assumed.
|
|
234
210
|
* @return Created middleware.
|
|
235
211
|
*/
|
|
236
|
-
function factory(webpackConfig, options) {
|
|
237
|
-
const ops = (
|
|
212
|
+
export default function factory(webpackConfig, options) {
|
|
213
|
+
const ops = defaults({
|
|
214
|
+
...options
|
|
215
|
+
}, {
|
|
238
216
|
beforeRender: async () => Promise.resolve({}),
|
|
239
217
|
maxSsrRounds: 10,
|
|
240
218
|
ssrTimeout: 1000,
|
|
@@ -248,18 +226,18 @@ function factory(webpackConfig, options) {
|
|
|
248
226
|
defaultLogLevel: ops.defaultLoggerLogLevel
|
|
249
227
|
});
|
|
250
228
|
const buildInfo = ops.buildInfo ?? getBuildInfo(webpackConfig.context);
|
|
251
|
-
|
|
229
|
+
setBuildInfo(buildInfo);
|
|
252
230
|
|
|
253
231
|
// publicPath from webpack.output has a trailing slash at the end.
|
|
254
232
|
const {
|
|
255
233
|
publicPath,
|
|
256
234
|
path: outputPath
|
|
257
235
|
} = webpackConfig.output;
|
|
258
|
-
const manifestLink =
|
|
236
|
+
const manifestLink = fs.existsSync(`${outputPath}/manifest.json`) ? `<link rel="manifest" href="${publicPath}manifest.json">` : '';
|
|
259
237
|
|
|
260
238
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
261
239
|
|
|
262
|
-
const cache = ops.staticCacheController ? new
|
|
240
|
+
const cache = ops.staticCacheController ? new Cache(ops.staticCacheSize) : null;
|
|
263
241
|
const CHUNK_GROUPS = readChunkGroupsJson(outputPath);
|
|
264
242
|
|
|
265
243
|
// TODO: Look at it later.
|
|
@@ -286,7 +264,7 @@ function factory(webpackConfig, options) {
|
|
|
286
264
|
res.send(buffer);
|
|
287
265
|
} else {
|
|
288
266
|
await new Promise((done, failed) => {
|
|
289
|
-
|
|
267
|
+
brotliDecompress(buffer, (error, html) => {
|
|
290
268
|
if (error) failed(error);else {
|
|
291
269
|
let h = html.toString();
|
|
292
270
|
if (!ops.noCsp) {
|
|
@@ -310,17 +288,12 @@ function factory(webpackConfig, options) {
|
|
|
310
288
|
}
|
|
311
289
|
}
|
|
312
290
|
const brr = ops.beforeRender(req, sanitizedConfig);
|
|
313
|
-
const
|
|
291
|
+
const {
|
|
314
292
|
configToInject,
|
|
315
293
|
extraScripts,
|
|
316
294
|
initialState
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
iv
|
|
320
|
-
}] = await Promise.all([
|
|
321
|
-
// NOTE: Written this way to avoid triggering the "await-thenable"
|
|
322
|
-
// ESLint rule.
|
|
323
|
-
brr instanceof Promise ? brr : Promise.resolve(brr), prepareCipher(buildInfo.key)]);
|
|
295
|
+
} = await brr;
|
|
296
|
+
const [cipher, iv] = prepareCipher(buildInfo.key);
|
|
324
297
|
let helmet;
|
|
325
298
|
|
|
326
299
|
// Gets the mapping between code chunk names and their asset files.
|
|
@@ -328,9 +301,9 @@ function factory(webpackConfig, options) {
|
|
|
328
301
|
// attached to the request (in dev mode), or from a file output during
|
|
329
302
|
// the build (in prod mode).
|
|
330
303
|
let chunkGroups;
|
|
331
|
-
const webpackStats = (
|
|
304
|
+
const webpackStats = get(res.locals, 'webpack.devMiddleware.stats');
|
|
332
305
|
if (webpackStats) {
|
|
333
|
-
chunkGroups = (
|
|
306
|
+
chunkGroups = mapValues(webpackStats.toJson({
|
|
334
307
|
all: false,
|
|
335
308
|
chunkGroups: true
|
|
336
309
|
}).namedChunkGroups, item => item.assets?.map(({
|
|
@@ -375,14 +348,14 @@ function factory(webpackConfig, options) {
|
|
|
375
348
|
// TODO: prerenderToNodeStream has (abort) "signal" option,
|
|
376
349
|
// and we should wire it up to the SSR timeout below.
|
|
377
350
|
const helmetContext = {};
|
|
378
|
-
void
|
|
351
|
+
void prerenderToNodeStream(/*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
379
352
|
initialState: ssrContext.state,
|
|
380
353
|
ssrContext: ssrContext,
|
|
381
|
-
children: /*#__PURE__*/(
|
|
354
|
+
children: /*#__PURE__*/_jsx(StaticRouter, {
|
|
382
355
|
location: req.url,
|
|
383
|
-
children: /*#__PURE__*/(
|
|
356
|
+
children: /*#__PURE__*/_jsx(HelmetProvider, {
|
|
384
357
|
context: helmetContext,
|
|
385
|
-
children: /*#__PURE__*/(
|
|
358
|
+
children: /*#__PURE__*/_jsx(App2, {})
|
|
386
359
|
})
|
|
387
360
|
})
|
|
388
361
|
}), {
|
|
@@ -400,7 +373,7 @@ function factory(webpackConfig, options) {
|
|
|
400
373
|
stream = await renderPass();
|
|
401
374
|
if (!ssrContext.dirty) break;
|
|
402
375
|
const timeout = ops.ssrTimeout + ssrStart - Date.now();
|
|
403
|
-
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending),
|
|
376
|
+
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending), timer(timeout).then(() => false)]));
|
|
404
377
|
if (bailed) break;
|
|
405
378
|
}
|
|
406
379
|
let logMsg;
|
|
@@ -417,7 +390,7 @@ function factory(webpackConfig, options) {
|
|
|
417
390
|
return;
|
|
418
391
|
}
|
|
419
392
|
await new Promise(ready => {
|
|
420
|
-
stream.pipe(new
|
|
393
|
+
stream.pipe(new Writable({
|
|
421
394
|
destroy: ready,
|
|
422
395
|
write: (chunk, _, done) => {
|
|
423
396
|
appHtmlMarkup += chunk.toString();
|
|
@@ -432,7 +405,7 @@ function factory(webpackConfig, options) {
|
|
|
432
405
|
* contains decryption key and is able to decode it at the client side.
|
|
433
406
|
* Hovewer, for a number of reasons, encryption of injected data is still
|
|
434
407
|
* better than injection of a plain text. */
|
|
435
|
-
const payload = (
|
|
408
|
+
const payload = serializeJs({
|
|
436
409
|
CHUNK_GROUPS: chunkGroups,
|
|
437
410
|
CONFIG: configToInject ?? sanitizedConfig,
|
|
438
411
|
ISTATE: ssrContext.state
|
|
@@ -440,9 +413,7 @@ function factory(webpackConfig, options) {
|
|
|
440
413
|
ignoreFunction: true,
|
|
441
414
|
unsafe: true
|
|
442
415
|
});
|
|
443
|
-
cipher.update(
|
|
444
|
-
cipher.finish();
|
|
445
|
-
const INJ = _nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);
|
|
416
|
+
const INJ = Buffer.concat([iv, cipher.update(payload, 'utf8'), cipher.final()]).toString('base64');
|
|
446
417
|
const chunkSet = new Set();
|
|
447
418
|
|
|
448
419
|
// TODO: "main" chunk has to be added explicitly,
|
|
@@ -501,7 +472,7 @@ function factory(webpackConfig, options) {
|
|
|
501
472
|
// Note: waiting for the caching to complete is not strictly necessary,
|
|
502
473
|
// but it greately simplifies testing, and error reporting.
|
|
503
474
|
await new Promise((done, failed) => {
|
|
504
|
-
|
|
475
|
+
brotliCompress(html, (error, buffer) => {
|
|
505
476
|
if (error) failed(error);else {
|
|
506
477
|
const b = buffer;
|
|
507
478
|
b.nonce = req.nonce;
|