@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.6

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.
Files changed (130) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/dist/js/modern/constants.js +32 -25
  3. package/dist/js/modern/index.js +11 -6
  4. package/dist/js/modern/libs/context/context.js +52 -84
  5. package/dist/js/modern/libs/context/index.js +5 -2
  6. package/dist/js/modern/libs/hook-api/index.js +44 -35
  7. package/dist/js/modern/libs/hook-api/route.js +6 -7
  8. package/dist/js/modern/libs/hook-api/template.js +20 -34
  9. package/dist/js/modern/libs/loadConfig.js +45 -24
  10. package/dist/js/modern/libs/metrics.js +3 -4
  11. package/dist/js/modern/libs/proxy.js +68 -37
  12. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
  13. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
  14. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
  15. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
  16. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
  17. package/dist/js/modern/libs/render/cache/index.js +88 -54
  18. package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
  19. package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
  20. package/dist/js/modern/libs/render/cache/spr.js +133 -117
  21. package/dist/js/modern/libs/render/cache/type.js +0 -1
  22. package/dist/js/modern/libs/render/cache/util.js +71 -39
  23. package/dist/js/modern/libs/render/index.js +76 -56
  24. package/dist/js/modern/libs/render/measure.js +38 -27
  25. package/dist/js/modern/libs/render/reader.js +65 -62
  26. package/dist/js/modern/libs/render/ssr.js +50 -32
  27. package/dist/js/modern/libs/render/static.js +50 -33
  28. package/dist/js/modern/libs/render/type.js +9 -6
  29. package/dist/js/modern/libs/route/index.js +8 -15
  30. package/dist/js/modern/libs/route/matcher.js +20 -34
  31. package/dist/js/modern/libs/route/route.js +9 -18
  32. package/dist/js/modern/libs/serve-file.js +33 -20
  33. package/dist/js/modern/server/index.js +150 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +384 -422
  36. package/dist/js/modern/type.js +0 -1
  37. package/dist/js/modern/utils.js +62 -43
  38. package/dist/js/modern/worker-server.js +34 -14
  39. package/dist/js/node/constants.js +53 -30
  40. package/dist/js/node/index.js +37 -57
  41. package/dist/js/node/libs/context/context.js +83 -94
  42. package/dist/js/node/libs/context/index.js +28 -13
  43. package/dist/js/node/libs/hook-api/index.js +76 -48
  44. package/dist/js/node/libs/hook-api/route.js +26 -11
  45. package/dist/js/node/libs/hook-api/template.js +41 -39
  46. package/dist/js/node/libs/loadConfig.js +73 -35
  47. package/dist/js/node/libs/metrics.js +25 -9
  48. package/dist/js/node/libs/proxy.js +89 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
  54. package/dist/js/node/libs/render/cache/index.js +110 -64
  55. package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
  57. package/dist/js/node/libs/render/cache/spr.js +161 -129
  58. package/dist/js/node/libs/render/cache/type.js +15 -5
  59. package/dist/js/node/libs/render/cache/util.js +99 -45
  60. package/dist/js/node/libs/render/index.js +106 -67
  61. package/dist/js/node/libs/render/measure.js +58 -31
  62. package/dist/js/node/libs/render/reader.js +95 -70
  63. package/dist/js/node/libs/render/ssr.js +80 -47
  64. package/dist/js/node/libs/render/static.js +79 -40
  65. package/dist/js/node/libs/render/type.js +31 -12
  66. package/dist/js/node/libs/route/index.js +31 -26
  67. package/dist/js/node/libs/route/matcher.js +40 -41
  68. package/dist/js/node/libs/route/route.js +29 -22
  69. package/dist/js/node/libs/serve-file.js +66 -32
  70. package/dist/js/node/server/index.js +168 -160
  71. package/dist/js/node/server/modern-server-split.js +72 -22
  72. package/dist/js/node/server/modern-server.js +403 -445
  73. package/dist/js/node/type.js +15 -3
  74. package/dist/js/node/utils.js +85 -52
  75. package/dist/js/node/worker-server.js +57 -21
  76. package/dist/js/treeshaking/constants.js +26 -25
  77. package/dist/js/treeshaking/index.js +10 -10
  78. package/dist/js/treeshaking/libs/context/context.js +268 -237
  79. package/dist/js/treeshaking/libs/context/index.js +3 -3
  80. package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
  81. package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
  82. package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
  83. package/dist/js/treeshaking/libs/loadConfig.js +80 -37
  84. package/dist/js/treeshaking/libs/metrics.js +4 -10
  85. package/dist/js/treeshaking/libs/proxy.js +240 -76
  86. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
  87. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
  88. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
  89. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
  90. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
  91. package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
  92. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
  93. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
  94. package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
  95. package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
  96. package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
  97. package/dist/js/treeshaking/libs/render/index.js +228 -95
  98. package/dist/js/treeshaking/libs/render/measure.js +142 -57
  99. package/dist/js/treeshaking/libs/render/reader.js +325 -177
  100. package/dist/js/treeshaking/libs/render/ssr.js +220 -95
  101. package/dist/js/treeshaking/libs/render/static.js +210 -78
  102. package/dist/js/treeshaking/libs/render/type.js +7 -6
  103. package/dist/js/treeshaking/libs/route/index.js +125 -89
  104. package/dist/js/treeshaking/libs/route/matcher.js +132 -107
  105. package/dist/js/treeshaking/libs/route/route.js +40 -26
  106. package/dist/js/treeshaking/libs/serve-file.js +177 -68
  107. package/dist/js/treeshaking/server/index.js +493 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1048 -909
  110. package/dist/js/treeshaking/type.js +1 -1
  111. package/dist/js/treeshaking/utils.js +138 -81
  112. package/dist/js/treeshaking/worker-server.js +176 -55
  113. package/dist/types/index.d.ts +2 -0
  114. package/dist/types/libs/context/context.d.ts +4 -1
  115. package/dist/types/libs/loadConfig.d.ts +1 -0
  116. package/dist/types/libs/render/cache/index.d.ts +2 -0
  117. package/dist/types/libs/render/cache/spr.d.ts +2 -0
  118. package/dist/types/libs/route/route.d.ts +0 -1
  119. package/dist/types/server/index.d.ts +3 -0
  120. package/dist/types/utils.d.ts +1 -1
  121. package/dist/types/worker-server.d.ts +1 -2
  122. package/package.json +7 -14
  123. package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
  124. package/dist/js/modern/libs/render/modern/index.js +0 -37
  125. package/dist/js/node/libs/render/modern/browser-list.js +0 -14
  126. package/dist/js/node/libs/render/modern/index.js +0 -46
  127. package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
  128. package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
  129. package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
  130. package/dist/types/libs/render/modern/index.d.ts +0 -3
@@ -1,41 +1,93 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ var __export = (target, all) => {
34
+ for (var name in all)
35
+ __defProp(target, name, { get: all[name], enumerable: true });
36
+ };
37
+ var __copyProps = (to, from, except, desc) => {
38
+ if (from && typeof from === "object" || typeof from === "function") {
39
+ for (let key of __getOwnPropNames(from))
40
+ if (!__hasOwnProp.call(to, key) && key !== except)
41
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
42
+ }
43
+ return to;
44
+ };
45
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
46
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
47
+ mod
48
+ ));
49
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
+ var __async = (__this, __arguments, generator) => {
51
+ return new Promise((resolve, reject) => {
52
+ var fulfilled = (value) => {
53
+ try {
54
+ step(generator.next(value));
55
+ } catch (e) {
56
+ reject(e);
57
+ }
58
+ };
59
+ var rejected = (value) => {
60
+ try {
61
+ step(generator.throw(value));
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ };
66
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
67
+ step((generator = generator.apply(__this, __arguments)).next());
68
+ });
69
+ };
70
+ var modern_server_exports = {};
71
+ __export(modern_server_exports, {
72
+ ModernServer: () => ModernServer
5
73
  });
6
- exports.ModernServer = void 0;
7
- var _http = require("http");
8
- var _util = _interopRequireDefault(require("util"));
9
- var _path = _interopRequireDefault(require("path"));
10
- var _utils = require("@modern-js/utils");
11
- var _route = require("../libs/route");
12
- var _render = require("../libs/render");
13
- var _serveFile = require("../libs/serve-file");
14
- var _utils2 = require("../utils");
15
- var reader = _interopRequireWildcard(require("../libs/render/reader"));
16
- var _proxy = require("../libs/proxy");
17
- var _context = require("../libs/context");
18
- var _template = require("../libs/hook-api/template");
19
- var _constants = require("../constants");
20
- var _hookApi = require("../libs/hook-api");
21
- const _excluded = ["getMiddlewares"];
22
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
28
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
29
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
- const API_DIR = './api';
31
- const SERVER_DIR = './server';
74
+ module.exports = __toCommonJS(modern_server_exports);
75
+ var import_http = require("http");
76
+ var import_path = __toESM(require("path"));
77
+ var import_utils = require("@modern-js/utils");
78
+ var import_route = require("../libs/route");
79
+ var import_render = require("../libs/render");
80
+ var import_serve_file = require("../libs/serve-file");
81
+ var import_utils2 = require("../utils");
82
+ var reader = __toESM(require("../libs/render/reader"));
83
+ var import_proxy = require("../libs/proxy");
84
+ var import_context = require("../libs/context");
85
+ var import_template = require("../libs/hook-api/template");
86
+ var import_constants = require("../constants");
87
+ var import_hook_api = require("../libs/hook-api");
88
+ const API_DIR = "./api";
89
+ const SERVER_DIR = "./server";
32
90
  class ModernServer {
33
- // appDirectory
34
-
35
- // product dist dir
36
-
37
- // work on src or dist
38
-
39
91
  constructor({
40
92
  pwd,
41
93
  config,
@@ -46,469 +98,373 @@ class ModernServer {
46
98
  runMode,
47
99
  proxyTarget
48
100
  }) {
49
- _defineProperty(this, "pwd", void 0);
50
- _defineProperty(this, "distDir", void 0);
51
- _defineProperty(this, "workDir", void 0);
52
- _defineProperty(this, "router", void 0);
53
- _defineProperty(this, "conf", void 0);
54
- _defineProperty(this, "handlers", []);
55
- _defineProperty(this, "presetRoutes", void 0);
56
- _defineProperty(this, "runner", void 0);
57
- _defineProperty(this, "logger", void 0);
58
- _defineProperty(this, "metrics", void 0);
59
- _defineProperty(this, "runMode", void 0);
60
- _defineProperty(this, "reader", reader);
61
- _defineProperty(this, "proxyTarget", void 0);
62
- _defineProperty(this, "staticFileHandler", void 0);
63
- _defineProperty(this, "routeRenderHandler", void 0);
64
- _defineProperty(this, "beforeRouteHandler", null);
65
- _defineProperty(this, "frameWebHandler", null);
66
- _defineProperty(this, "frameAPIHandler", null);
67
- _defineProperty(this, "proxyHandler", null);
68
- _defineProperty(this, "_handler", void 0);
69
- _defineProperty(this, "staticGenerate", void 0);
70
- require('ignore-styles');
101
+ this.handlers = [];
102
+ this.reader = reader;
103
+ this.beforeRouteHandler = null;
104
+ this.frameWebHandler = null;
105
+ this.frameAPIHandler = null;
106
+ this.proxyHandler = null;
107
+ require("ignore-styles");
71
108
  this.pwd = pwd;
72
- this.distDir = _path.default.join(pwd, config.output.path || 'dist');
109
+ this.distDir = import_path.default.join(pwd, config.output.path || "dist");
73
110
  this.workDir = this.distDir;
74
111
  this.conf = config;
75
- (0, _utils2.debug)('server conf', this.conf);
112
+ (0, import_utils2.debug)("server conf", this.conf);
76
113
  this.logger = logger;
77
114
  this.metrics = metrics;
78
- this.router = new _route.RouteMatchManager();
115
+ this.router = new import_route.RouteMatchManager();
79
116
  this.presetRoutes = routes;
80
117
  this.proxyTarget = proxyTarget;
81
118
  this.staticGenerate = staticGenerate || false;
82
- this.runMode = runMode || _constants.RUN_MODE.FULL;
83
- // process.env.BUILD_TYPE = `${this.staticGenerate ? 'ssg' : 'ssr'}`;
119
+ this.runMode = runMode || import_constants.RUN_MODE.FULL;
84
120
  }
85
-
86
- // server prepare
87
- async onInit(runner, app) {
88
- var _conf$bff;
89
- this.runner = runner;
90
- const {
91
- distDir,
92
- staticGenerate,
93
- conf
94
- } = this;
95
- (0, _utils2.debug)('final server conf', this.conf);
96
- // proxy handler, each proxy has own handler
97
- this.proxyHandler = (0, _proxy.createProxyHandler)((_conf$bff = conf.bff) === null || _conf$bff === void 0 ? void 0 : _conf$bff.proxy);
98
- if (this.proxyHandler) {
99
- this.proxyHandler.forEach(handler => {
100
- this.addHandler(handler);
121
+ onInit(runner, app) {
122
+ return __async(this, null, function* () {
123
+ var _a;
124
+ this.runner = runner;
125
+ const { distDir, staticGenerate, conf } = this;
126
+ (0, import_utils2.debug)("final server conf", this.conf);
127
+ this.proxyHandler = (0, import_proxy.createProxyHandler)((_a = conf.bff) == null ? void 0 : _a.proxy);
128
+ if (this.proxyHandler) {
129
+ this.proxyHandler.forEach((handler) => {
130
+ this.addHandler(handler);
131
+ });
132
+ }
133
+ this.reader.init();
134
+ app.on("close", () => {
135
+ this.reader.close();
101
136
  });
102
- }
103
-
104
- // start file reader
105
- this.reader.init();
106
- app.on('close', () => {
107
- this.reader.close();
108
- });
109
-
110
- // use preset routes priority
111
- const usageRoutes = this.filterRoutes(this.getRoutes());
112
- this.router.reset(usageRoutes);
113
-
114
- // warmup ssr bundle in production env
115
- this.warmupSSRBundle();
116
- await this.prepareFrameHandler();
117
- await this.prepareBeforeRouteHandler(usageRoutes, distDir);
118
-
119
- // Only work when without setting `assetPrefix`.
120
- // Setting `assetPrefix` means these resources should be uploaded to CDN.
121
- const staticPathRegExp = (0, _utils2.getStaticReg)(this.conf.output || {}, this.conf.html);
122
- this.staticFileHandler = (0, _serveFile.createStaticFileHandler)([{
123
- path: staticPathRegExp,
124
- target: distDir
125
- }], this.conf.output);
126
- this.routeRenderHandler = (0, _render.createRenderHandler)({
127
- distDir,
128
- staticGenerate
137
+ const usageRoutes = this.filterRoutes(this.getRoutes());
138
+ this.router.reset(usageRoutes);
139
+ this.warmupSSRBundle();
140
+ yield this.prepareFrameHandler();
141
+ yield this.prepareBeforeRouteHandler(usageRoutes, distDir);
142
+ const staticPathRegExp = (0, import_utils2.getStaticReg)(
143
+ this.conf.output || {},
144
+ this.conf.html
145
+ );
146
+ this.staticFileHandler = (0, import_serve_file.createStaticFileHandler)(
147
+ [
148
+ {
149
+ path: staticPathRegExp,
150
+ target: distDir
151
+ }
152
+ ],
153
+ this.conf.output
154
+ );
155
+ this.routeRenderHandler = (0, import_render.createRenderHandler)({
156
+ distDir,
157
+ staticGenerate
158
+ });
159
+ yield this.setupBeforeProdMiddleware();
160
+ this.addHandler(this.staticFileHandler);
161
+ this.addHandler(import_serve_file.faviconFallbackHandler);
162
+ this.addBeforeRouteHandler();
163
+ this.addHandler(this.routeHandler.bind(this));
164
+ this.compose();
129
165
  });
130
- await this.setupBeforeProdMiddleware();
131
- this.addHandler(this.staticFileHandler);
132
-
133
- // execute after staticFileHandler, can rename to staticFallbackHandler if needed.
134
- this.addHandler(_serveFile.faviconFallbackHandler);
135
- this.addBeforeRouteHandler();
136
- this.addHandler(this.routeHandler.bind(this));
137
-
138
- // compose middlewares to http handler
139
- this.compose();
140
166
  }
141
-
142
- // server ready
143
167
  onRepack(_) {
144
- // empty
145
168
  }
146
169
  addBeforeRouteHandler() {
147
- this.addHandler(async (context, next) => {
170
+ this.addHandler((context, next) => __async(this, null, function* () {
148
171
  if (this.beforeRouteHandler) {
149
- await this.beforeRouteHandler(context);
172
+ yield this.beforeRouteHandler(context);
150
173
  if (this.isSend(context.res)) {
151
174
  return;
152
175
  }
153
176
  }
154
- // eslint-disable-next-line consistent-return
155
177
  return next();
156
- });
178
+ }));
157
179
  }
158
- onServerChange({
159
- filepath
160
- }) {
161
- const {
162
- pwd
163
- } = this;
164
- const {
165
- api,
166
- server
167
- } = _constants.AGGRED_DIR;
168
- const apiPath = _path.default.normalize(_path.default.join(pwd, api));
169
- const serverPath = _path.default.normalize(_path.default.join(pwd, server));
180
+ onServerChange({ filepath }) {
181
+ const { pwd } = this;
182
+ const { api, server } = import_constants.AGGRED_DIR;
183
+ const apiPath = import_path.default.normalize(import_path.default.join(pwd, api));
184
+ const serverPath = import_path.default.normalize(import_path.default.join(pwd, server));
170
185
  const onlyApi = filepath.startsWith(apiPath);
171
186
  const onlyWeb = filepath.startsWith(serverPath);
172
- this.prepareFrameHandler({
173
- onlyWeb,
174
- onlyApi
175
- });
187
+ this.prepareFrameHandler({ onlyWeb, onlyApi });
176
188
  }
177
-
178
- // exposed requestHandler
179
189
  getRequestHandler() {
180
190
  return this.requestHandler.bind(this);
181
191
  }
182
- async render(req, res, url) {
183
- req.logger = this.logger;
184
- req.metrics = this.metrics;
185
- const context = (0, _context.createContext)(req, res);
186
- const matched = this.router.match(url || context.path);
187
- if (!matched) {
188
- return null;
189
- }
190
- const route = matched.generate(context.url);
191
- const result = await this.handleWeb(context, route);
192
- if (!result) {
193
- return null;
194
- }
195
- return result.content.toString();
192
+ render(req, res, url) {
193
+ return __async(this, null, function* () {
194
+ req.logger = this.logger;
195
+ req.metrics = this.metrics;
196
+ const context = (0, import_context.createContext)(req, res);
197
+ const matched = this.router.match(url || context.path);
198
+ if (!matched) {
199
+ return null;
200
+ }
201
+ const route = matched.generate(context.url);
202
+ const result = yield this.handleWeb(context, route);
203
+ if (!result) {
204
+ return null;
205
+ }
206
+ return result.content.toString();
207
+ });
196
208
  }
197
- async createHTTPServer(handler) {
198
- return (0, _http.createServer)(handler);
209
+ createHTTPServer(handler) {
210
+ return __async(this, null, function* () {
211
+ return (0, import_http.createServer)(handler);
212
+ });
199
213
  }
200
-
201
- /* —————————————————————— function will be overwrite —————————————————————— */
202
- // get routes info
203
214
  getRoutes() {
204
- // Preferred to use preset routes
205
215
  if (this.presetRoutes) {
206
216
  return this.presetRoutes;
207
217
  }
208
-
209
- // read routes from spec file
210
- const file = _path.default.join(this.distDir, _utils.ROUTE_SPEC_FILE);
211
- if (_utils.fs.existsSync(file)) {
212
- const content = _utils.fs.readJSONSync(file);
218
+ const file = import_path.default.join(this.distDir, import_utils.ROUTE_SPEC_FILE);
219
+ if (import_utils.fs.existsSync(file)) {
220
+ const content = import_utils.fs.readJSONSync(file);
213
221
  return content.routes;
214
222
  }
215
223
  return [];
216
224
  }
217
-
218
- // add promisify request handler to server
219
- // handler should do not do more things after invoke next
220
225
  addHandler(handler) {
221
- if (handler[Symbol.toStringTag] === 'AsyncFunction') {
222
- this.handlers.push(handler);
223
- } else {
224
- this.handlers.push(_util.default.promisify(handler));
225
- }
226
+ this.handlers.push(handler);
226
227
  }
227
-
228
- // return 404 page
229
228
  render404(context) {
230
- context.error(_constants.ERROR_DIGEST.ENOTF, '404 Not Found');
229
+ context.error(import_constants.ERROR_DIGEST.ENOTF, "404 Not Found");
231
230
  this.renderErrorPage(context, 404);
232
231
  }
233
- async prepareBeforeRouteHandler(specs, distDir) {
234
- const {
235
- runner
236
- } = this;
237
- const handler = await runner.preparebeforeRouteHandler({
238
- serverRoutes: specs,
239
- distDir
240
- }, {
241
- onLast: () => null
232
+ prepareBeforeRouteHandler(specs, distDir) {
233
+ return __async(this, null, function* () {
234
+ const { runner } = this;
235
+ const handler = yield runner.preparebeforeRouteHandler(
236
+ {
237
+ serverRoutes: specs,
238
+ distDir
239
+ },
240
+ {
241
+ onLast: () => null
242
+ }
243
+ );
244
+ this.beforeRouteHandler = handler;
242
245
  });
243
- this.beforeRouteHandler = handler;
244
246
  }
245
-
246
- // gather frame extension and get framework handler
247
- async prepareFrameHandler(options) {
248
- const {
249
- workDir,
250
- runner
251
- } = this;
252
- const {
253
- onlyApi,
254
- onlyWeb
255
- } = options || {};
256
-
257
- // server hook, gather plugin inject
258
- const _createMiddlewareColl = (0, _utils2.createMiddlewareCollecter)(),
259
- {
260
- getMiddlewares
261
- } = _createMiddlewareColl,
262
- collector = _objectWithoutProperties(_createMiddlewareColl, _excluded);
263
- await runner.gather(collector);
264
- const {
265
- api: pluginAPIExt,
266
- web: pluginWebExt
267
- } = getMiddlewares();
268
- const apiDir = _path.default.join(workDir, API_DIR);
269
- const serverDir = _path.default.join(workDir, SERVER_DIR);
270
-
271
- // get api or web server handler from server-framework plugin
272
- if ((await _utils.fs.pathExists(_path.default.join(serverDir))) && !onlyApi) {
273
- const webExtension = (0, _utils2.mergeExtension)(pluginWebExt);
274
- this.frameWebHandler = await this.prepareWebHandler(webExtension);
275
- }
276
- if (_utils.fs.existsSync(apiDir) && !onlyWeb) {
277
- const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt);
278
- this.frameAPIHandler = await this.prepareAPIHandler(apiExtension);
279
- }
247
+ prepareFrameHandler(options) {
248
+ return __async(this, null, function* () {
249
+ const { workDir, runner } = this;
250
+ const { onlyApi, onlyWeb } = options || {};
251
+ const _a = (0, import_utils2.createMiddlewareCollecter)(), { getMiddlewares } = _a, collector = __objRest(_a, ["getMiddlewares"]);
252
+ yield runner.gather(collector);
253
+ const { api: pluginAPIExt, web: pluginWebExt } = getMiddlewares();
254
+ const apiDir = import_path.default.join(workDir, API_DIR);
255
+ const serverDir = import_path.default.join(workDir, SERVER_DIR);
256
+ if ((yield import_utils.fs.pathExists(import_path.default.join(serverDir))) && !onlyApi) {
257
+ const webExtension = (0, import_utils2.mergeExtension)(pluginWebExt);
258
+ this.frameWebHandler = yield this.prepareWebHandler(webExtension);
259
+ }
260
+ if (import_utils.fs.existsSync(apiDir) && !onlyWeb) {
261
+ const apiExtension = (0, import_utils2.mergeExtension)(pluginAPIExt);
262
+ this.frameAPIHandler = yield this.prepareAPIHandler(apiExtension);
263
+ }
264
+ });
280
265
  }
281
- async prepareWebHandler(extension) {
282
- const {
283
- workDir,
284
- runner
285
- } = this;
286
- const handler = await runner.prepareWebServer({
287
- pwd: workDir,
288
- config: extension
289
- }, {
290
- onLast: () => null
266
+ prepareWebHandler(extension) {
267
+ return __async(this, null, function* () {
268
+ const { workDir, runner } = this;
269
+ const handler = yield runner.prepareWebServer(
270
+ {
271
+ pwd: workDir,
272
+ config: extension
273
+ },
274
+ { onLast: () => null }
275
+ );
276
+ return handler;
291
277
  });
292
- return handler;
293
278
  }
294
- async prepareAPIHandler(extension) {
295
- const {
296
- workDir,
297
- runner,
298
- conf
299
- } = this;
300
- const {
301
- bff
302
- } = conf;
303
- const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
304
- return runner.prepareApiServer({
305
- pwd: workDir,
306
- config: extension,
307
- prefix: Array.isArray(prefix) ? prefix[0] : prefix
308
- }, {
309
- onLast: () => null
279
+ prepareAPIHandler(extension) {
280
+ return __async(this, null, function* () {
281
+ const { workDir, runner, conf } = this;
282
+ const { bff } = conf;
283
+ const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
284
+ return runner.prepareApiServer(
285
+ {
286
+ pwd: workDir,
287
+ config: extension,
288
+ prefix: Array.isArray(prefix) ? prefix[0] : prefix
289
+ },
290
+ { onLast: () => null }
291
+ );
310
292
  });
311
293
  }
312
294
  filterRoutes(routes) {
313
295
  return routes;
314
296
  }
315
- async setupBeforeProdMiddleware() {
316
- const {
317
- conf,
318
- runner
319
- } = this;
320
- const preMiddleware = await runner.beforeProdServer(conf);
321
- preMiddleware.flat().forEach(mid => {
322
- this.addHandler(mid);
297
+ setupBeforeProdMiddleware() {
298
+ return __async(this, null, function* () {
299
+ const { conf, runner } = this;
300
+ const preMiddleware = yield runner.beforeProdServer(conf);
301
+ preMiddleware.flat().forEach((mid) => {
302
+ this.addHandler(mid);
303
+ });
323
304
  });
324
305
  }
325
- async handleAPI(context) {
326
- const {
327
- req,
328
- res
329
- } = context;
330
- if (!this.frameAPIHandler) {
331
- throw new Error('can not found api handler');
332
- }
333
- await this.frameAPIHandler(req, res);
306
+ handleAPI(context) {
307
+ return __async(this, null, function* () {
308
+ const { req, res } = context;
309
+ if (!this.frameAPIHandler) {
310
+ throw new Error("can not found api handler");
311
+ }
312
+ yield this.frameAPIHandler(req, res);
313
+ });
334
314
  }
335
- async handleWeb(context, route) {
336
- return this.routeRenderHandler({
337
- ctx: context,
338
- route,
339
- runner: this.runner
315
+ handleWeb(context, route) {
316
+ return __async(this, null, function* () {
317
+ return this.routeRenderHandler({
318
+ ctx: context,
319
+ route,
320
+ runner: this.runner
321
+ });
340
322
  });
341
323
  }
342
- async proxy() {
343
- return null;
324
+ proxy() {
325
+ return __async(this, null, function* () {
326
+ return null;
327
+ });
344
328
  }
345
-
346
- // warmup ssr function
347
329
  warmupSSRBundle() {
348
- const {
349
- distDir
350
- } = this;
330
+ const { distDir } = this;
351
331
  const bundles = this.router.getBundles();
352
- bundles.forEach(bundle => {
353
- const filepath = _path.default.join(distDir, bundle);
354
- // if error, just throw and let process die
332
+ bundles.forEach((bundle) => {
333
+ const filepath = import_path.default.join(distDir, bundle);
355
334
  require(filepath);
356
335
  });
357
336
  }
358
337
  createContext(req, res, options = {}) {
359
- return (0, _context.createContext)(req, res, options);
338
+ return (0, import_context.createContext)(req, res, options);
360
339
  }
361
-
362
- /* —————————————————————— private function —————————————————————— */
363
- // handler route.json, include api / csr / ssr
364
- async routeHandler(context) {
365
- const {
366
- res
367
- } = context;
368
-
369
- // match routes in the route spec
370
- const matched = this.router.match(context.path);
371
- if (!matched) {
372
- this.render404(context);
373
- return;
374
- }
375
-
376
- // route is api service
377
- let route = matched.generate(context.url);
378
- if (route.isApi) {
379
- await this.handleAPI(context);
380
- return;
381
- }
382
- const afterMatchContext = (0, _hookApi.createAfterMatchContext)(context, route.entryName);
383
-
384
- // only full mode run server hook
385
- if (this.runMode === _constants.RUN_MODE.FULL) {
386
- await this.runner.afterMatch(afterMatchContext, {
387
- onLast: _utils2.noop
388
- });
389
- }
390
- if (this.isSend(res)) {
391
- return;
392
- }
393
- const {
394
- current,
395
- url,
396
- status
397
- } = afterMatchContext.router;
398
- // redirect to another url
399
- if (url) {
400
- this.redirect(res, url, status);
401
- return;
402
- }
403
-
404
- // rewrite to another entry
405
- if (route.entryName !== current) {
406
- const matched = this.router.matchEntry(current);
340
+ routeHandler(context) {
341
+ return __async(this, null, function* () {
342
+ const { res } = context;
343
+ const matched = this.router.match(context.path);
407
344
  if (!matched) {
408
345
  this.render404(context);
409
346
  return;
410
347
  }
411
- route = matched.generate(context.url);
412
- }
413
- context.setParams(route.params);
414
- context.setServerData('router', {
415
- baseUrl: route.urlPath,
416
- params: route.params
417
- });
418
- if (this.frameWebHandler) {
419
- res.locals = res.locals || {};
420
- const middlewareContext = (0, _hookApi.createMiddlewareContext)(context);
421
- await this.frameWebHandler(middlewareContext);
422
- res.locals = _objectSpread(_objectSpread({}, res.locals), middlewareContext.response.locals);
423
- }
424
-
425
- // frameWebHandler has process request
426
- if (this.isSend(res)) {
427
- return;
428
- }
429
- if (route.responseHeaders) {
430
- Object.keys(route.responseHeaders).forEach(key => {
431
- const value = route.responseHeaders[key];
432
- if (value) {
433
- context.res.setHeader(key, value);
348
+ let route = matched.generate(context.url);
349
+ if (route.isApi) {
350
+ yield this.handleAPI(context);
351
+ return;
352
+ }
353
+ const afterMatchContext = (0, import_hook_api.createAfterMatchContext)(context, route.entryName);
354
+ if (this.runMode === import_constants.RUN_MODE.FULL) {
355
+ yield this.runner.afterMatch(afterMatchContext, { onLast: import_utils2.noop });
356
+ }
357
+ if (this.isSend(res)) {
358
+ return;
359
+ }
360
+ const { current, url, status } = afterMatchContext.router;
361
+ if (url) {
362
+ this.redirect(res, url, status);
363
+ return;
364
+ }
365
+ if (route.entryName !== current) {
366
+ const matched2 = this.router.matchEntry(current);
367
+ if (!matched2) {
368
+ this.render404(context);
369
+ return;
434
370
  }
371
+ route = matched2.generate(context.url);
372
+ }
373
+ context.setParams(route.params);
374
+ context.setServerData("router", {
375
+ baseUrl: route.urlPath,
376
+ params: route.params
435
377
  });
436
- }
437
- const renderResult = await this.handleWeb(context, route);
438
- if (!renderResult) {
439
- this.render404(context);
440
- return;
441
- }
442
-
443
- // React Router navigation
444
- if (renderResult.redirect) {
445
- this.redirect(res, renderResult.content, renderResult.statusCode);
446
- return;
447
- }
448
- if (this.isSend(res)) {
449
- return;
450
- }
451
- res.setHeader('content-type', renderResult.contentType);
452
- const {
453
- contentStream
454
- } = renderResult;
455
- if (contentStream) {
456
- contentStream.pipe((0, _template.templateInjectableStream)({
457
- prependHead: route.entryName ? `<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>` : undefined
458
- })).pipe(res);
459
- return;
460
- }
461
- let response = renderResult.content;
462
- if (route.entryName) {
463
- const afterRenderContext = (0, _hookApi.createAfterRenderContext)(context, response.toString());
464
-
465
- // only full mode run server hook
466
- // FIXME: how to run server hook in streaming
467
- if (this.runMode === _constants.RUN_MODE.FULL) {
468
- await this.runner.afterRender(afterRenderContext, {
469
- onLast: _utils2.noop
378
+ if (this.frameWebHandler) {
379
+ res.locals = res.locals || {};
380
+ const middlewareContext = (0, import_hook_api.createMiddlewareContext)(context);
381
+ yield this.frameWebHandler(middlewareContext);
382
+ res.locals = __spreadValues(__spreadValues({}, res.locals), middlewareContext.response.locals);
383
+ }
384
+ if (this.isSend(res)) {
385
+ return;
386
+ }
387
+ if (route.responseHeaders) {
388
+ Object.keys(route.responseHeaders).forEach((key) => {
389
+ const value = route.responseHeaders[key];
390
+ if (value) {
391
+ context.res.setHeader(key, value);
392
+ }
470
393
  });
471
394
  }
395
+ const renderResult = yield this.handleWeb(context, route);
396
+ if (!renderResult) {
397
+ this.render404(context);
398
+ return;
399
+ }
400
+ if (renderResult.redirect) {
401
+ this.redirect(
402
+ res,
403
+ renderResult.content,
404
+ renderResult.statusCode
405
+ );
406
+ return;
407
+ }
472
408
  if (this.isSend(res)) {
473
409
  return;
474
410
  }
475
-
476
- // It will inject _SERVER_DATA twice, when SSG mode.
477
- // The first time was in ssg html created, the seoncd time was in prod-server start.
478
- // but the second wound causes route error.
479
- // To ensure that the second injection fails, the _SERVER_DATA inject at the front of head,
480
- afterRenderContext.template.prependHead(`<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>`);
481
- response = afterRenderContext.template.get();
482
- }
483
- res.end(response);
411
+ res.setHeader("content-type", renderResult.contentType);
412
+ const { contentStream } = renderResult;
413
+ if (contentStream) {
414
+ contentStream.pipe(
415
+ (0, import_template.templateInjectableStream)({
416
+ prependHead: route.entryName ? `<script>window._SERVER_DATA=${JSON.stringify(
417
+ context.serverData
418
+ )}<\/script>` : void 0
419
+ })
420
+ ).pipe(res);
421
+ return;
422
+ }
423
+ let response = renderResult.content;
424
+ if (route.entryName) {
425
+ const afterRenderContext = (0, import_hook_api.createAfterRenderContext)(
426
+ context,
427
+ response.toString()
428
+ );
429
+ if (this.runMode === import_constants.RUN_MODE.FULL) {
430
+ yield this.runner.afterRender(afterRenderContext, { onLast: import_utils2.noop });
431
+ }
432
+ if (this.isSend(res)) {
433
+ return;
434
+ }
435
+ afterRenderContext.template.prependHead(
436
+ `<script>window._SERVER_DATA=${JSON.stringify(
437
+ context.serverData
438
+ )}<\/script>`
439
+ );
440
+ response = afterRenderContext.template.get();
441
+ }
442
+ res.end(response);
443
+ });
484
444
  }
485
445
  isSend(res) {
486
446
  if (res.headersSent) {
487
447
  return true;
488
448
  }
489
- if (res.getHeader('Location') && (0, _utils2.isRedirect)(res.statusCode)) {
449
+ if (res.getHeader("Location") && (0, import_utils2.isRedirect)(res.statusCode)) {
490
450
  res.end();
491
451
  return true;
492
452
  }
493
453
  return false;
494
454
  }
495
-
496
- // compose handlers and create the final handler
497
455
  compose() {
498
- const {
499
- handlers
500
- } = this;
456
+ const { handlers } = this;
501
457
  if (!Array.isArray(handlers)) {
502
- throw new TypeError('Middleware stack must be an array!');
458
+ throw new TypeError("Middleware stack must be an array!");
503
459
  }
504
460
  for (const fn of handlers) {
505
- if (typeof fn !== 'function') {
506
- throw new TypeError('Middleware must be composed of functions!');
461
+ if (typeof fn !== "function") {
462
+ throw new TypeError("Middleware must be composed of functions!");
507
463
  }
508
464
  }
509
465
  this._handler = (context, next) => {
510
466
  let i = 0;
511
- const dispatch = error => {
467
+ const dispatch = (error) => {
512
468
  if (error) {
513
469
  return this.onError(context, error);
514
470
  }
@@ -516,16 +472,22 @@ class ModernServer {
516
472
  if (!handler) {
517
473
  return next();
518
474
  }
519
- return handler(context, dispatch).catch(onError);
475
+ try {
476
+ const result = handler(context, dispatch);
477
+ if ((0, import_utils.isPromise)(result)) {
478
+ return result.catch(onError);
479
+ }
480
+ } catch (e) {
481
+ return onError(e);
482
+ }
520
483
  };
521
- const onError = err => {
484
+ const onError = (err) => {
522
485
  this.onError(context, err);
523
486
  };
524
487
  return dispatch();
525
488
  };
526
489
  }
527
490
  requestHandler(req, res, next = () => {
528
- // empty
529
491
  }) {
530
492
  res.statusCode = 200;
531
493
  req.logger = this.logger;
@@ -536,8 +498,8 @@ class ModernServer {
536
498
  } catch (e) {
537
499
  this.logger.error(e);
538
500
  res.statusCode = 500;
539
- res.setHeader('content-type', _utils.mime.contentType('html'));
540
- return res.end((0, _utils2.createErrorDocument)(500, _constants.ERROR_PAGE_TEXT[500]));
501
+ res.setHeader("content-type", import_utils.mime.contentType("html"));
502
+ return res.end((0, import_utils2.createErrorDocument)(500, import_constants.ERROR_PAGE_TEXT[500]));
541
503
  }
542
504
  try {
543
505
  return this._handler(context, next);
@@ -546,50 +508,46 @@ class ModernServer {
546
508
  }
547
509
  }
548
510
  redirect(res, url, status = 302) {
549
- res.setHeader('Location', url);
511
+ res.setHeader("Location", url);
550
512
  res.statusCode = status;
551
513
  res.end();
552
514
  }
553
515
  onError(context, err) {
554
- context.error(_constants.ERROR_DIGEST.EINTER, err);
516
+ context.error(import_constants.ERROR_DIGEST.EINTER, err);
555
517
  this.renderErrorPage(context, 500);
556
518
  }
557
- async renderErrorPage(context, status) {
558
- const {
559
- res
560
- } = context;
561
- context.status = status;
562
- res.setHeader('content-type', _utils.mime.contentType('html'));
563
- const statusPage = `/${status}`;
564
- const customErrorPage = `/_error`;
565
- const matched = this.router.match(statusPage) || this.router.match(customErrorPage);
566
- // if no custom status page find
567
-
568
- if (matched) {
569
- const route = matched.generate(context.url);
570
- const {
571
- entryName
572
- } = route;
573
- // check entryName, avoid matched '/' route
574
- if (entryName === status.toString() || entryName === '_error') {
575
- try {
576
- const file = await this.routeRenderHandler({
577
- route,
578
- ctx: context,
579
- runner: this.runner
580
- });
581
- if (file) {
582
- context.res.end(file.content);
583
- return;
519
+ renderErrorPage(context, status) {
520
+ return __async(this, null, function* () {
521
+ const { res } = context;
522
+ context.status = status;
523
+ res.setHeader("content-type", import_utils.mime.contentType("html"));
524
+ const statusPage = `/${status}`;
525
+ const customErrorPage = `/_error`;
526
+ const matched = this.router.match(statusPage) || this.router.match(customErrorPage);
527
+ if (matched) {
528
+ const route = matched.generate(context.url);
529
+ const { entryName } = route;
530
+ if (entryName === status.toString() || entryName === "_error") {
531
+ try {
532
+ const file = yield this.routeRenderHandler({
533
+ route,
534
+ ctx: context,
535
+ runner: this.runner
536
+ });
537
+ if (file) {
538
+ context.res.end(file.content);
539
+ return;
540
+ }
541
+ } catch (e) {
584
542
  }
585
- } catch (e) {
586
- // just catch error when the rendering error occurred in the custom error page.
587
543
  }
588
544
  }
589
- }
590
- const text = _constants.ERROR_PAGE_TEXT[status] || _constants.ERROR_PAGE_TEXT[500];
591
- context.res.end((0, _utils2.createErrorDocument)(status, text));
545
+ const text = import_constants.ERROR_PAGE_TEXT[status] || import_constants.ERROR_PAGE_TEXT[500];
546
+ context.res.end((0, import_utils2.createErrorDocument)(status, text));
547
+ });
592
548
  }
593
549
  }
594
- /* eslint-enable max-lines */
595
- exports.ModernServer = ModernServer;
550
+ // Annotate the CommonJS export names for ESM import in node:
551
+ 0 && (module.exports = {
552
+ ModernServer
553
+ });