@dr.pogodin/react-utils 1.47.0-alpha.1 → 1.47.0-alpha.11
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 +57 -44
- 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 +3 -183
- 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 +22 -50
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +83 -92
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +58 -62
- 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 +18 -19
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +24 -28
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +19 -19
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +12 -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 -21
- 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 +24 -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 +54 -46
- 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 +17 -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 +2 -6
- 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 -11
- 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 -6
- 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 -22
- 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 -7
- package/build/types-code/server/index.d.ts +6 -11
- package/build/types-code/server/utils/index.d.ts +1 -1
- 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 +55 -44
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +15 -21
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +2 -4
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +1 -15
- package/build/web/index.js.map +1 -1
- package/build/web/server/index.js +12 -21
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +34 -40
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +14 -11
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/index.js +1 -1
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +1 -1
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js +1 -1
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +3 -3
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +1 -1
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +1 -1
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +1 -1
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +1 -1
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +3 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +3 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +4 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +2 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/utils/config.js +38 -14
- 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 +3 -2
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +27 -20
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/webpack.js +13 -7
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.js +12 -6
- package/config/babel/webpack.js +6 -1
- package/config/jest/default.js +8 -2
- package/config/jest/setup.js +8 -1
- package/config/webpack/app-base.js +23 -15
- package/config/webpack/app-development.js +2 -3
- package/config/webpack/lib-base.js +1 -2
- package/package.json +35 -25
- package/types.d.ts +1 -6
- package/node-entry.js +0 -15
- package/src/client/getInj.ts +0 -51
- package/src/client/index.tsx +0 -43
- package/src/client/init.ts +0 -52
- package/src/index.ts +0 -79
- package/src/server/Cache.ts +0 -61
- package/src/server/index.ts +0 -249
- package/src/server/renderer.tsx +0 -653
- package/src/server/server.ts +0 -332
- package/src/server/utils/errors.ts +0 -122
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Button/style.scss +0 -54
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Checkbox/theme.scss +0 -63
- package/src/shared/components/GenericLink/index.tsx +0 -141
- package/src/shared/components/GenericLink/style.scss +0 -3
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Input/theme.scss +0 -52
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/base-theme.scss +0 -38
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/Modal/styles.scss +0 -3
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/PageLayout/base-theme.scss +0 -30
- package/src/shared/components/PageLayout/index.tsx +0 -51
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/TextArea/style.scss +0 -68
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/Throbber/theme.scss +0 -26
- package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
- package/src/shared/components/WithTooltip/default-theme.scss +0 -36
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/YouTubeVideo/base.scss +0 -15
- package/src/shared/components/YouTubeVideo/index.tsx +0 -73
- package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
- package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
- package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
- package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
- package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/Switch/theme.scss +0 -39
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -28
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/isomorphy/index.ts +0 -36
- package/src/shared/utils/jest/E2eSsrEnv.ts +0 -305
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/jest/index.ts +0 -215
- package/src/shared/utils/splitComponent.tsx +0 -275
- package/src/shared/utils/time.ts +0 -101
- package/src/shared/utils/webpack.ts +0 -74
- package/src/styles/_global/reset.css +0 -52
- package/src/styles/_mixins/fonts.scss +0 -40
- package/src/styles/_mixins/media.scss +0 -150
- package/src/styles/_mixins/typography.scss +0 -83
- package/src/styles/global.scss +0 -11
- package/src/styles/mixins.scss +0 -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
|
+
export * from "./utils/index.js";
|
|
14
|
+
export { getDefaultCspSettings, SCRIPT_LOCATIONS };
|
|
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 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,4 @@ async function launchServer(webpackConfig, options = {}) {
|
|
|
224
199
|
httpServer
|
|
225
200
|
};
|
|
226
201
|
}
|
|
227
|
-
launchServer.SCRIPT_LOCATIONS = _renderer.SCRIPT_LOCATIONS;
|
|
228
|
-
launchServer.getDefaultCspSettings = _server.getDefaultCspSettings;
|
|
229
|
-
launchServer.errors = _utils.errors;
|
|
230
202
|
//# 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","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\nexport * from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport {\n getDefaultCspSettings,\n SCRIPT_LOCATIONS,\n type ServerT,\n};\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 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"],"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;AAW3C,SACEF,qBAAqB,EACrBC,gBAAgB;;AAIlB;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,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,OAAO,eAAeK,YAAYA,CAChCC,aAA4B,EAC5BC,OAAiB,GAAG,CAAC,CAAC,EAIrB;EACD;EACA,MAAMC,GAAG,GAAGf,SAAS,CAACc,OAAO,CAAC;;EAE9B;EACAC,GAAG,CAACP,IAAI,GAAGF,aAAa,CAACS,GAAG,CAACP,IAAI,IAAIQ,OAAO,CAACC,GAAG,CAACC,IAAI,IAAI,IAAI,CAAC;EAC9DjB,QAAQ,CAACc,GAAG,EAAE;IAAEI,aAAa,EAAE;EAAK,CAAC,CAAC;;EAEtC;EACA;EACAJ,GAAG,CAACK,MAAM,KAAKf,gBAAgB,CAAC;IAC9BgB,eAAe,EAAEN,GAAG,CAACO;EACvB,CAAC,CAAC;;EAEF;EACA,MAAMC,aAAa,GAAG,MAAMrB,aAAa,CAACW,aAAa,EAAEE,GAAG,CAAC;EAE7D,IAAIS,UAAuB;EAC3B,IAAIT,GAAG,CAAChB,KAAK,EAAE;IACbyB,UAAU,GAAGzB,KAAK,CAAC0B,YAAY,CAAC;MAC9BC,IAAI,EAAEX,GAAG,CAAChB,KAAK,CAAC2B,IAAI;MACpBC,GAAG,EAAEZ,GAAG,CAAChB,KAAK,CAAC4B;IACjB,CAAC,EAAEJ,aAAsC,CAAC;EAC5C,CAAC,MAAMC,UAAU,GAAG1B,IAAI,CAAC2B,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","ignoreList":[]}
|
|
@@ -1,41 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
|
1
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/es.iterator.for-each.js";
|
|
3
|
+
import "core-js/modules/es.iterator.map.js";
|
|
4
|
+
import "core-js/modules/es.set.difference.v2.js";
|
|
5
|
+
import "core-js/modules/es.set.intersection.v2.js";
|
|
6
|
+
import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
7
|
+
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
8
|
+
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
9
|
+
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
10
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
11
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
12
|
+
import "core-js/modules/es.iterator.for-each.js";
|
|
13
|
+
import "core-js/modules/es.iterator.map.js";
|
|
14
|
+
import "core-js/modules/es.set.difference.v2.js";
|
|
15
|
+
import "core-js/modules/es.set.intersection.v2.js";
|
|
16
|
+
import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
17
|
+
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
18
|
+
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
19
|
+
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
20
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
34
21
|
/**
|
|
35
22
|
* ExpressJS middleware for server-side rendering of a ReactJS app.
|
|
36
23
|
*/
|
|
37
24
|
|
|
38
|
-
|
|
25
|
+
import { Buffer } from 'node:buffer';
|
|
26
|
+
import { createCipheriv, randomBytes } from 'node:crypto';
|
|
27
|
+
import fs from 'node:fs';
|
|
28
|
+
import path from 'node:path';
|
|
29
|
+
import { Writable } from 'node:stream';
|
|
30
|
+
import { brotliCompress, brotliDecompress } from 'node:zlib';
|
|
31
|
+
import winston from 'winston';
|
|
32
|
+
import { GlobalStateProvider, SsrContext } from '@dr.pogodin/react-global-state';
|
|
33
|
+
import { timer } from '@dr.pogodin/js-utils';
|
|
34
|
+
import { cloneDeep, defaults, get, mapValues } from 'lodash-es';
|
|
35
|
+
import config from 'config';
|
|
36
|
+
import { prerenderToNodeStream } from 'react-dom/static';
|
|
37
|
+
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
38
|
+
import { StaticRouter } from 'react-router';
|
|
39
|
+
import serializeJs from 'serialize-javascript';
|
|
40
|
+
import { setBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
|
|
41
|
+
import Cache from "./Cache.js"; // @ts-expect-error "Property 'SECRET' does not exist on type 'IConfig'."
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
44
|
+
const {
|
|
45
|
+
SECRET,
|
|
46
|
+
...sanitizedConfig
|
|
47
|
+
} = config;
|
|
39
48
|
|
|
40
49
|
// Note: These type definitions for logger are copied from Winston logger,
|
|
41
50
|
// then simplified to make it easier to fit an alternative logger into this
|
|
@@ -46,17 +55,17 @@ const sanitizedConfig = (0, _omit.default)(_config.default, 'SECRET');
|
|
|
46
55
|
|
|
47
56
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
48
57
|
|
|
49
|
-
let SCRIPT_LOCATIONS =
|
|
58
|
+
export let SCRIPT_LOCATIONS = /*#__PURE__*/function (SCRIPT_LOCATIONS) {
|
|
50
59
|
SCRIPT_LOCATIONS["BODY_OPEN"] = "BODY_OPEN";
|
|
51
60
|
SCRIPT_LOCATIONS["DEFAULT"] = "DEFAULT";
|
|
52
61
|
SCRIPT_LOCATIONS["HEAD_OPEN"] = "HEAD_OPEN";
|
|
53
62
|
return SCRIPT_LOCATIONS;
|
|
54
63
|
}({});
|
|
55
|
-
class ServerSsrContext extends
|
|
64
|
+
export class ServerSsrContext extends SsrContext {
|
|
56
65
|
chunks = [];
|
|
57
66
|
status = 200;
|
|
58
67
|
constructor(req, chunkGroups, initialState) {
|
|
59
|
-
super((
|
|
68
|
+
super(cloneDeep(initialState) ?? {});
|
|
60
69
|
this.chunkGroups = chunkGroups;
|
|
61
70
|
this.req = req;
|
|
62
71
|
}
|
|
@@ -70,10 +79,9 @@ class ServerSsrContext extends _reactGlobalState.SsrContext {
|
|
|
70
79
|
* @param context Webpack context path used during the build.
|
|
71
80
|
* @return Resolves to the build-time information.
|
|
72
81
|
*/
|
|
73
|
-
exports.ServerSsrContext = ServerSsrContext;
|
|
74
82
|
function getBuildInfo(context) {
|
|
75
|
-
const url =
|
|
76
|
-
return JSON.parse(
|
|
83
|
+
const url = path.resolve(context, '.build-info');
|
|
84
|
+
return JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
/**
|
|
@@ -85,10 +93,10 @@ function getBuildInfo(context) {
|
|
|
85
93
|
* @return
|
|
86
94
|
*/
|
|
87
95
|
function readChunkGroupsJson(buildDir) {
|
|
88
|
-
const url =
|
|
96
|
+
const url = path.resolve(buildDir, '__chunk_groups__.json');
|
|
89
97
|
let res;
|
|
90
98
|
try {
|
|
91
|
-
res = JSON.parse(
|
|
99
|
+
res = JSON.parse(fs.readFileSync(url, 'utf8'));
|
|
92
100
|
} catch {
|
|
93
101
|
// TODO: Should we message the error here somehow?
|
|
94
102
|
res = null;
|
|
@@ -98,27 +106,15 @@ function readChunkGroupsJson(buildDir) {
|
|
|
98
106
|
|
|
99
107
|
/**
|
|
100
108
|
* 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:
|
|
109
|
+
* @param key Encryption key (32-bit random, Base64-encoded key is expected).
|
|
110
|
+
* @return Returns a tuple of:
|
|
104
111
|
* 1. cipher - a new Cipher, ready for encryption;
|
|
105
112
|
* 2. iv - initial vector used by the cipher.
|
|
106
113
|
*/
|
|
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
|
-
});
|
|
114
|
+
function prepareCipher(key) {
|
|
115
|
+
const iv = randomBytes(16);
|
|
116
|
+
const cipher = createCipheriv('AES-256-CBC', Buffer.from(key, 'base64'), iv);
|
|
117
|
+
return [cipher, iv];
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
/**
|
|
@@ -126,7 +122,7 @@ async function prepareCipher(key) {
|
|
|
126
122
|
* are acceptable to the caller.
|
|
127
123
|
* @param req
|
|
128
124
|
*/
|
|
129
|
-
function isBrotliAcceptable(req) {
|
|
125
|
+
export function isBrotliAcceptable(req) {
|
|
130
126
|
const acceptable = req.get('accept-encoding');
|
|
131
127
|
if (acceptable) {
|
|
132
128
|
const ops = acceptable.split(',');
|
|
@@ -161,7 +157,7 @@ function groupExtraScripts(scripts = []) {
|
|
|
161
157
|
[SCRIPT_LOCATIONS.HEAD_OPEN]: ''
|
|
162
158
|
};
|
|
163
159
|
for (const script of scripts) {
|
|
164
|
-
if (
|
|
160
|
+
if (typeof script === 'string') {
|
|
165
161
|
if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;
|
|
166
162
|
} else if (script.code) {
|
|
167
163
|
if (script.location in res) res[script.location] += script.code;else throw Error(`Invalid location "${script.location}"`);
|
|
@@ -176,14 +172,14 @@ function groupExtraScripts(scripts = []) {
|
|
|
176
172
|
* @param {string} [options.defaultLogLevel='info']
|
|
177
173
|
* @return {object}
|
|
178
174
|
*/
|
|
179
|
-
function newDefaultLogger({
|
|
175
|
+
export function newDefaultLogger({
|
|
180
176
|
defaultLogLevel = 'info'
|
|
181
177
|
} = {}) {
|
|
182
178
|
const {
|
|
183
179
|
format,
|
|
184
180
|
transports
|
|
185
|
-
} =
|
|
186
|
-
return
|
|
181
|
+
} = winston;
|
|
182
|
+
return winston.createLogger({
|
|
187
183
|
format: format.combine(format.splat(), format.timestamp(), format.colorize(), format.printf(({
|
|
188
184
|
level,
|
|
189
185
|
message,
|
|
@@ -233,8 +229,10 @@ function newDefaultLogger({
|
|
|
233
229
|
* If undefined - infinite age is assumed.
|
|
234
230
|
* @return Created middleware.
|
|
235
231
|
*/
|
|
236
|
-
function factory(webpackConfig, options) {
|
|
237
|
-
const ops = (
|
|
232
|
+
export default function factory(webpackConfig, options) {
|
|
233
|
+
const ops = defaults({
|
|
234
|
+
...options
|
|
235
|
+
}, {
|
|
238
236
|
beforeRender: async () => Promise.resolve({}),
|
|
239
237
|
maxSsrRounds: 10,
|
|
240
238
|
ssrTimeout: 1000,
|
|
@@ -248,18 +246,18 @@ function factory(webpackConfig, options) {
|
|
|
248
246
|
defaultLogLevel: ops.defaultLoggerLogLevel
|
|
249
247
|
});
|
|
250
248
|
const buildInfo = ops.buildInfo ?? getBuildInfo(webpackConfig.context);
|
|
251
|
-
|
|
249
|
+
setBuildInfo(buildInfo);
|
|
252
250
|
|
|
253
251
|
// publicPath from webpack.output has a trailing slash at the end.
|
|
254
252
|
const {
|
|
255
253
|
publicPath,
|
|
256
254
|
path: outputPath
|
|
257
255
|
} = webpackConfig.output;
|
|
258
|
-
const manifestLink =
|
|
256
|
+
const manifestLink = fs.existsSync(`${outputPath}/manifest.json`) ? `<link rel="manifest" href="${publicPath}manifest.json">` : '';
|
|
259
257
|
|
|
260
258
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
261
259
|
|
|
262
|
-
const cache = ops.staticCacheController ? new
|
|
260
|
+
const cache = ops.staticCacheController ? new Cache(ops.staticCacheSize) : null;
|
|
263
261
|
const CHUNK_GROUPS = readChunkGroupsJson(outputPath);
|
|
264
262
|
|
|
265
263
|
// TODO: Look at it later.
|
|
@@ -286,7 +284,7 @@ function factory(webpackConfig, options) {
|
|
|
286
284
|
res.send(buffer);
|
|
287
285
|
} else {
|
|
288
286
|
await new Promise((done, failed) => {
|
|
289
|
-
|
|
287
|
+
brotliDecompress(buffer, (error, html) => {
|
|
290
288
|
if (error) failed(error);else {
|
|
291
289
|
let h = html.toString();
|
|
292
290
|
if (!ops.noCsp) {
|
|
@@ -310,17 +308,12 @@ function factory(webpackConfig, options) {
|
|
|
310
308
|
}
|
|
311
309
|
}
|
|
312
310
|
const brr = ops.beforeRender(req, sanitizedConfig);
|
|
313
|
-
const
|
|
311
|
+
const {
|
|
314
312
|
configToInject,
|
|
315
313
|
extraScripts,
|
|
316
314
|
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)]);
|
|
315
|
+
} = await brr;
|
|
316
|
+
const [cipher, iv] = prepareCipher(buildInfo.key);
|
|
324
317
|
let helmet;
|
|
325
318
|
|
|
326
319
|
// Gets the mapping between code chunk names and their asset files.
|
|
@@ -328,9 +321,9 @@ function factory(webpackConfig, options) {
|
|
|
328
321
|
// attached to the request (in dev mode), or from a file output during
|
|
329
322
|
// the build (in prod mode).
|
|
330
323
|
let chunkGroups;
|
|
331
|
-
const webpackStats = (
|
|
324
|
+
const webpackStats = get(res.locals, 'webpack.devMiddleware.stats');
|
|
332
325
|
if (webpackStats) {
|
|
333
|
-
chunkGroups = (
|
|
326
|
+
chunkGroups = mapValues(webpackStats.toJson({
|
|
334
327
|
all: false,
|
|
335
328
|
chunkGroups: true
|
|
336
329
|
}).namedChunkGroups, item => item.assets?.map(({
|
|
@@ -375,14 +368,14 @@ function factory(webpackConfig, options) {
|
|
|
375
368
|
// TODO: prerenderToNodeStream has (abort) "signal" option,
|
|
376
369
|
// and we should wire it up to the SSR timeout below.
|
|
377
370
|
const helmetContext = {};
|
|
378
|
-
void
|
|
371
|
+
void prerenderToNodeStream(/*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
379
372
|
initialState: ssrContext.state,
|
|
380
373
|
ssrContext: ssrContext,
|
|
381
|
-
children: /*#__PURE__*/(
|
|
374
|
+
children: /*#__PURE__*/_jsx(StaticRouter, {
|
|
382
375
|
location: req.url,
|
|
383
|
-
children: /*#__PURE__*/(
|
|
376
|
+
children: /*#__PURE__*/_jsx(HelmetProvider, {
|
|
384
377
|
context: helmetContext,
|
|
385
|
-
children: /*#__PURE__*/(
|
|
378
|
+
children: /*#__PURE__*/_jsx(App2, {})
|
|
386
379
|
})
|
|
387
380
|
})
|
|
388
381
|
}), {
|
|
@@ -400,7 +393,7 @@ function factory(webpackConfig, options) {
|
|
|
400
393
|
stream = await renderPass();
|
|
401
394
|
if (!ssrContext.dirty) break;
|
|
402
395
|
const timeout = ops.ssrTimeout + ssrStart - Date.now();
|
|
403
|
-
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending),
|
|
396
|
+
bailed = timeout <= 0 || !(await Promise.race([Promise.allSettled(ssrContext.pending), timer(timeout).then(() => false)]));
|
|
404
397
|
if (bailed) break;
|
|
405
398
|
}
|
|
406
399
|
let logMsg;
|
|
@@ -417,7 +410,7 @@ function factory(webpackConfig, options) {
|
|
|
417
410
|
return;
|
|
418
411
|
}
|
|
419
412
|
await new Promise(ready => {
|
|
420
|
-
stream.pipe(new
|
|
413
|
+
stream.pipe(new Writable({
|
|
421
414
|
destroy: ready,
|
|
422
415
|
write: (chunk, _, done) => {
|
|
423
416
|
appHtmlMarkup += chunk.toString();
|
|
@@ -432,7 +425,7 @@ function factory(webpackConfig, options) {
|
|
|
432
425
|
* contains decryption key and is able to decode it at the client side.
|
|
433
426
|
* Hovewer, for a number of reasons, encryption of injected data is still
|
|
434
427
|
* better than injection of a plain text. */
|
|
435
|
-
const payload = (
|
|
428
|
+
const payload = serializeJs({
|
|
436
429
|
CHUNK_GROUPS: chunkGroups,
|
|
437
430
|
CONFIG: configToInject ?? sanitizedConfig,
|
|
438
431
|
ISTATE: ssrContext.state
|
|
@@ -440,9 +433,7 @@ function factory(webpackConfig, options) {
|
|
|
440
433
|
ignoreFunction: true,
|
|
441
434
|
unsafe: true
|
|
442
435
|
});
|
|
443
|
-
cipher.update(
|
|
444
|
-
cipher.finish();
|
|
445
|
-
const INJ = _nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);
|
|
436
|
+
const INJ = Buffer.concat([iv, cipher.update(payload, 'utf8'), cipher.final()]).toString('base64');
|
|
446
437
|
const chunkSet = new Set();
|
|
447
438
|
|
|
448
439
|
// TODO: "main" chunk has to be added explicitly,
|
|
@@ -501,7 +492,7 @@ function factory(webpackConfig, options) {
|
|
|
501
492
|
// Note: waiting for the caching to complete is not strictly necessary,
|
|
502
493
|
// but it greately simplifies testing, and error reporting.
|
|
503
494
|
await new Promise((done, failed) => {
|
|
504
|
-
|
|
495
|
+
brotliCompress(html, (error, buffer) => {
|
|
505
496
|
if (error) failed(error);else {
|
|
506
497
|
const b = buffer;
|
|
507
498
|
b.nonce = req.nonce;
|