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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +69 -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 +42 -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 +144 -145
  34. package/dist/js/modern/server/modern-server-split.js +46 -12
  35. package/dist/js/modern/server/modern-server.js +377 -417
  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 +45 -30
  40. package/dist/js/node/index.js +31 -57
  41. package/dist/js/node/libs/context/context.js +79 -94
  42. package/dist/js/node/libs/context/index.js +23 -13
  43. package/dist/js/node/libs/hook-api/index.js +69 -48
  44. package/dist/js/node/libs/hook-api/route.js +22 -11
  45. package/dist/js/node/libs/hook-api/template.js +36 -39
  46. package/dist/js/node/libs/loadConfig.js +69 -35
  47. package/dist/js/node/libs/metrics.js +21 -9
  48. package/dist/js/node/libs/proxy.js +86 -44
  49. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
  50. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
  51. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
  52. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
  53. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -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 +50 -14
  56. package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
  57. package/dist/js/node/libs/render/cache/spr.js +156 -129
  58. package/dist/js/node/libs/render/cache/type.js +0 -5
  59. package/dist/js/node/libs/render/cache/util.js +88 -45
  60. package/dist/js/node/libs/render/index.js +102 -67
  61. package/dist/js/node/libs/render/measure.js +55 -31
  62. package/dist/js/node/libs/render/reader.js +87 -70
  63. package/dist/js/node/libs/render/ssr.js +76 -47
  64. package/dist/js/node/libs/render/static.js +75 -40
  65. package/dist/js/node/libs/render/type.js +27 -12
  66. package/dist/js/node/libs/route/index.js +26 -26
  67. package/dist/js/node/libs/route/matcher.js +36 -41
  68. package/dist/js/node/libs/route/route.js +25 -22
  69. package/dist/js/node/libs/serve-file.js +61 -32
  70. package/dist/js/node/server/index.js +160 -160
  71. package/dist/js/node/server/modern-server-split.js +68 -22
  72. package/dist/js/node/server/modern-server.js +395 -441
  73. package/dist/js/node/type.js +0 -3
  74. package/dist/js/node/utils.js +74 -52
  75. package/dist/js/node/worker-server.js +53 -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 +265 -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 +468 -327
  108. package/dist/js/treeshaking/server/modern-server-split.js +352 -144
  109. package/dist/js/treeshaking/server/modern-server.js +1046 -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,96 @@
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 __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ ModernServer: () => ModernServer
5
27
  });
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';
28
+ module.exports = __toCommonJS(stdin_exports);
29
+ var import_http = require("http");
30
+ var import_util = __toESM(require("util"));
31
+ var import_path = __toESM(require("path"));
32
+ var import_utils = require("@modern-js/utils");
33
+ var import_route = require("../libs/route");
34
+ var import_render = require("../libs/render");
35
+ var import_serve_file = require("../libs/serve-file");
36
+ var import_utils2 = require("../utils");
37
+ var reader = __toESM(require("../libs/render/reader"));
38
+ var import_proxy = require("../libs/proxy");
39
+ var import_context = require("../libs/context");
40
+ var import_template = require("../libs/hook-api/template");
41
+ var import_constants = require("../constants");
42
+ var import_hook_api = require("../libs/hook-api");
43
+ var __defProp2 = Object.defineProperty;
44
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
45
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
46
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
47
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
48
+ var __spreadValues = (a, b) => {
49
+ for (var prop in b || (b = {}))
50
+ if (__hasOwnProp2.call(b, prop))
51
+ __defNormalProp(a, prop, b[prop]);
52
+ if (__getOwnPropSymbols)
53
+ for (var prop of __getOwnPropSymbols(b)) {
54
+ if (__propIsEnum.call(b, prop))
55
+ __defNormalProp(a, prop, b[prop]);
56
+ }
57
+ return a;
58
+ };
59
+ var __objRest = (source, exclude) => {
60
+ var target = {};
61
+ for (var prop in source)
62
+ if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
63
+ target[prop] = source[prop];
64
+ if (source != null && __getOwnPropSymbols)
65
+ for (var prop of __getOwnPropSymbols(source)) {
66
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
67
+ target[prop] = source[prop];
68
+ }
69
+ return target;
70
+ };
71
+ var __async = (__this, __arguments, generator) => {
72
+ return new Promise((resolve, reject) => {
73
+ var fulfilled = (value) => {
74
+ try {
75
+ step(generator.next(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var rejected = (value) => {
81
+ try {
82
+ step(generator.throw(value));
83
+ } catch (e) {
84
+ reject(e);
85
+ }
86
+ };
87
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
88
+ step((generator = generator.apply(__this, __arguments)).next());
89
+ });
90
+ };
91
+ const API_DIR = "./api";
92
+ const SERVER_DIR = "./server";
32
93
  class ModernServer {
33
- // appDirectory
34
-
35
- // product dist dir
36
-
37
- // work on src or dist
38
-
39
94
  constructor({
40
95
  pwd,
41
96
  config,
@@ -46,469 +101,377 @@ class ModernServer {
46
101
  runMode,
47
102
  proxyTarget
48
103
  }) {
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');
104
+ this.handlers = [];
105
+ this.reader = reader;
106
+ this.beforeRouteHandler = null;
107
+ this.frameWebHandler = null;
108
+ this.frameAPIHandler = null;
109
+ this.proxyHandler = null;
110
+ require("ignore-styles");
71
111
  this.pwd = pwd;
72
- this.distDir = _path.default.join(pwd, config.output.path || 'dist');
112
+ this.distDir = import_path.default.join(pwd, config.output.path || "dist");
73
113
  this.workDir = this.distDir;
74
114
  this.conf = config;
75
- (0, _utils2.debug)('server conf', this.conf);
115
+ (0, import_utils2.debug)("server conf", this.conf);
76
116
  this.logger = logger;
77
117
  this.metrics = metrics;
78
- this.router = new _route.RouteMatchManager();
118
+ this.router = new import_route.RouteMatchManager();
79
119
  this.presetRoutes = routes;
80
120
  this.proxyTarget = proxyTarget;
81
121
  this.staticGenerate = staticGenerate || false;
82
- this.runMode = runMode || _constants.RUN_MODE.FULL;
83
- // process.env.BUILD_TYPE = `${this.staticGenerate ? 'ssg' : 'ssr'}`;
122
+ this.runMode = runMode || import_constants.RUN_MODE.FULL;
84
123
  }
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);
124
+ onInit(runner, app) {
125
+ return __async(this, null, function* () {
126
+ var _a;
127
+ this.runner = runner;
128
+ const { distDir, staticGenerate, conf } = this;
129
+ (0, import_utils2.debug)("final server conf", this.conf);
130
+ this.proxyHandler = (0, import_proxy.createProxyHandler)((_a = conf.bff) == null ? void 0 : _a.proxy);
131
+ if (this.proxyHandler) {
132
+ this.proxyHandler.forEach((handler) => {
133
+ this.addHandler(handler);
134
+ });
135
+ }
136
+ this.reader.init();
137
+ app.on("close", () => {
138
+ this.reader.close();
101
139
  });
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
140
+ const usageRoutes = this.filterRoutes(this.getRoutes());
141
+ this.router.reset(usageRoutes);
142
+ this.warmupSSRBundle();
143
+ yield this.prepareFrameHandler();
144
+ yield this.prepareBeforeRouteHandler(usageRoutes, distDir);
145
+ const staticPathRegExp = (0, import_utils2.getStaticReg)(
146
+ this.conf.output || {},
147
+ this.conf.html
148
+ );
149
+ this.staticFileHandler = (0, import_serve_file.createStaticFileHandler)(
150
+ [
151
+ {
152
+ path: staticPathRegExp,
153
+ target: distDir
154
+ }
155
+ ],
156
+ this.conf.output
157
+ );
158
+ this.routeRenderHandler = (0, import_render.createRenderHandler)({
159
+ distDir,
160
+ staticGenerate
161
+ });
162
+ yield this.setupBeforeProdMiddleware();
163
+ this.addHandler(this.staticFileHandler);
164
+ this.addHandler(import_serve_file.faviconFallbackHandler);
165
+ this.addBeforeRouteHandler();
166
+ this.addHandler(this.routeHandler.bind(this));
167
+ this.compose();
129
168
  });
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
169
  }
141
-
142
- // server ready
143
170
  onRepack(_) {
144
- // empty
145
171
  }
146
172
  addBeforeRouteHandler() {
147
- this.addHandler(async (context, next) => {
173
+ this.addHandler((context, next) => __async(this, null, function* () {
148
174
  if (this.beforeRouteHandler) {
149
- await this.beforeRouteHandler(context);
175
+ yield this.beforeRouteHandler(context);
150
176
  if (this.isSend(context.res)) {
151
177
  return;
152
178
  }
153
179
  }
154
- // eslint-disable-next-line consistent-return
155
180
  return next();
156
- });
181
+ }));
157
182
  }
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));
183
+ onServerChange({ filepath }) {
184
+ const { pwd } = this;
185
+ const { api, server } = import_constants.AGGRED_DIR;
186
+ const apiPath = import_path.default.normalize(import_path.default.join(pwd, api));
187
+ const serverPath = import_path.default.normalize(import_path.default.join(pwd, server));
170
188
  const onlyApi = filepath.startsWith(apiPath);
171
189
  const onlyWeb = filepath.startsWith(serverPath);
172
- this.prepareFrameHandler({
173
- onlyWeb,
174
- onlyApi
175
- });
190
+ this.prepareFrameHandler({ onlyWeb, onlyApi });
176
191
  }
177
-
178
- // exposed requestHandler
179
192
  getRequestHandler() {
180
193
  return this.requestHandler.bind(this);
181
194
  }
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();
195
+ render(req, res, url) {
196
+ return __async(this, null, function* () {
197
+ req.logger = this.logger;
198
+ req.metrics = this.metrics;
199
+ const context = (0, import_context.createContext)(req, res);
200
+ const matched = this.router.match(url || context.path);
201
+ if (!matched) {
202
+ return null;
203
+ }
204
+ const route = matched.generate(context.url);
205
+ const result = yield this.handleWeb(context, route);
206
+ if (!result) {
207
+ return null;
208
+ }
209
+ return result.content.toString();
210
+ });
196
211
  }
197
- async createHTTPServer(handler) {
198
- return (0, _http.createServer)(handler);
212
+ createHTTPServer(handler) {
213
+ return __async(this, null, function* () {
214
+ return (0, import_http.createServer)(handler);
215
+ });
199
216
  }
200
-
201
- /* —————————————————————— function will be overwrite —————————————————————— */
202
- // get routes info
203
217
  getRoutes() {
204
- // Preferred to use preset routes
205
218
  if (this.presetRoutes) {
206
219
  return this.presetRoutes;
207
220
  }
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);
221
+ const file = import_path.default.join(this.distDir, import_utils.ROUTE_SPEC_FILE);
222
+ if (import_utils.fs.existsSync(file)) {
223
+ const content = import_utils.fs.readJSONSync(file);
213
224
  return content.routes;
214
225
  }
215
226
  return [];
216
227
  }
217
-
218
- // add promisify request handler to server
219
- // handler should do not do more things after invoke next
220
228
  addHandler(handler) {
221
- if (handler[Symbol.toStringTag] === 'AsyncFunction') {
229
+ if (handler[Symbol.toStringTag] === "AsyncFunction") {
222
230
  this.handlers.push(handler);
223
231
  } else {
224
- this.handlers.push(_util.default.promisify(handler));
232
+ this.handlers.push(import_util.default.promisify(handler));
225
233
  }
226
234
  }
227
-
228
- // return 404 page
229
235
  render404(context) {
230
- context.error(_constants.ERROR_DIGEST.ENOTF, '404 Not Found');
236
+ context.error(import_constants.ERROR_DIGEST.ENOTF, "404 Not Found");
231
237
  this.renderErrorPage(context, 404);
232
238
  }
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
239
+ prepareBeforeRouteHandler(specs, distDir) {
240
+ return __async(this, null, function* () {
241
+ const { runner } = this;
242
+ const handler = yield runner.preparebeforeRouteHandler(
243
+ {
244
+ serverRoutes: specs,
245
+ distDir
246
+ },
247
+ {
248
+ onLast: () => null
249
+ }
250
+ );
251
+ this.beforeRouteHandler = handler;
242
252
  });
243
- this.beforeRouteHandler = handler;
244
253
  }
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
- }
254
+ prepareFrameHandler(options) {
255
+ return __async(this, null, function* () {
256
+ const { workDir, runner } = this;
257
+ const { onlyApi, onlyWeb } = options || {};
258
+ const _a = (0, import_utils2.createMiddlewareCollecter)(), { getMiddlewares } = _a, collector = __objRest(_a, ["getMiddlewares"]);
259
+ yield runner.gather(collector);
260
+ const { api: pluginAPIExt, web: pluginWebExt } = getMiddlewares();
261
+ const apiDir = import_path.default.join(workDir, API_DIR);
262
+ const serverDir = import_path.default.join(workDir, SERVER_DIR);
263
+ if ((yield import_utils.fs.pathExists(import_path.default.join(serverDir))) && !onlyApi) {
264
+ const webExtension = (0, import_utils2.mergeExtension)(pluginWebExt);
265
+ this.frameWebHandler = yield this.prepareWebHandler(webExtension);
266
+ }
267
+ if (import_utils.fs.existsSync(apiDir) && !onlyWeb) {
268
+ const apiExtension = (0, import_utils2.mergeExtension)(pluginAPIExt);
269
+ this.frameAPIHandler = yield this.prepareAPIHandler(apiExtension);
270
+ }
271
+ });
280
272
  }
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
273
+ prepareWebHandler(extension) {
274
+ return __async(this, null, function* () {
275
+ const { workDir, runner } = this;
276
+ const handler = yield runner.prepareWebServer(
277
+ {
278
+ pwd: workDir,
279
+ config: extension
280
+ },
281
+ { onLast: () => null }
282
+ );
283
+ return handler;
291
284
  });
292
- return handler;
293
285
  }
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
286
+ prepareAPIHandler(extension) {
287
+ return __async(this, null, function* () {
288
+ const { workDir, runner, conf } = this;
289
+ const { bff } = conf;
290
+ const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
291
+ return runner.prepareApiServer(
292
+ {
293
+ pwd: workDir,
294
+ config: extension,
295
+ prefix: Array.isArray(prefix) ? prefix[0] : prefix
296
+ },
297
+ { onLast: () => null }
298
+ );
310
299
  });
311
300
  }
312
301
  filterRoutes(routes) {
313
302
  return routes;
314
303
  }
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);
304
+ setupBeforeProdMiddleware() {
305
+ return __async(this, null, function* () {
306
+ const { conf, runner } = this;
307
+ const preMiddleware = yield runner.beforeProdServer(conf);
308
+ preMiddleware.flat().forEach((mid) => {
309
+ this.addHandler(mid);
310
+ });
323
311
  });
324
312
  }
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);
313
+ handleAPI(context) {
314
+ return __async(this, null, function* () {
315
+ const { req, res } = context;
316
+ if (!this.frameAPIHandler) {
317
+ throw new Error("can not found api handler");
318
+ }
319
+ yield this.frameAPIHandler(req, res);
320
+ });
334
321
  }
335
- async handleWeb(context, route) {
336
- return this.routeRenderHandler({
337
- ctx: context,
338
- route,
339
- runner: this.runner
322
+ handleWeb(context, route) {
323
+ return __async(this, null, function* () {
324
+ return this.routeRenderHandler({
325
+ ctx: context,
326
+ route,
327
+ runner: this.runner
328
+ });
340
329
  });
341
330
  }
342
- async proxy() {
343
- return null;
331
+ proxy() {
332
+ return __async(this, null, function* () {
333
+ return null;
334
+ });
344
335
  }
345
-
346
- // warmup ssr function
347
336
  warmupSSRBundle() {
348
- const {
349
- distDir
350
- } = this;
337
+ const { distDir } = this;
351
338
  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
339
+ bundles.forEach((bundle) => {
340
+ const filepath = import_path.default.join(distDir, bundle);
355
341
  require(filepath);
356
342
  });
357
343
  }
358
344
  createContext(req, res, options = {}) {
359
- return (0, _context.createContext)(req, res, options);
345
+ return (0, import_context.createContext)(req, res, options);
360
346
  }
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);
347
+ routeHandler(context) {
348
+ return __async(this, null, function* () {
349
+ const { res } = context;
350
+ const matched = this.router.match(context.path);
407
351
  if (!matched) {
408
352
  this.render404(context);
409
353
  return;
410
354
  }
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);
355
+ let route = matched.generate(context.url);
356
+ if (route.isApi) {
357
+ yield this.handleAPI(context);
358
+ return;
359
+ }
360
+ const afterMatchContext = (0, import_hook_api.createAfterMatchContext)(context, route.entryName);
361
+ if (this.runMode === import_constants.RUN_MODE.FULL) {
362
+ yield this.runner.afterMatch(afterMatchContext, { onLast: import_utils2.noop });
363
+ }
364
+ if (this.isSend(res)) {
365
+ return;
366
+ }
367
+ const { current, url, status } = afterMatchContext.router;
368
+ if (url) {
369
+ this.redirect(res, url, status);
370
+ return;
371
+ }
372
+ if (route.entryName !== current) {
373
+ const matched2 = this.router.matchEntry(current);
374
+ if (!matched2) {
375
+ this.render404(context);
376
+ return;
434
377
  }
378
+ route = matched2.generate(context.url);
379
+ }
380
+ context.setParams(route.params);
381
+ context.setServerData("router", {
382
+ baseUrl: route.urlPath,
383
+ params: route.params
435
384
  });
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
385
+ if (this.frameWebHandler) {
386
+ res.locals = res.locals || {};
387
+ const middlewareContext = (0, import_hook_api.createMiddlewareContext)(context);
388
+ yield this.frameWebHandler(middlewareContext);
389
+ res.locals = __spreadValues(__spreadValues({}, res.locals), middlewareContext.response.locals);
390
+ }
391
+ if (this.isSend(res)) {
392
+ return;
393
+ }
394
+ if (route.responseHeaders) {
395
+ Object.keys(route.responseHeaders).forEach((key) => {
396
+ const value = route.responseHeaders[key];
397
+ if (value) {
398
+ context.res.setHeader(key, value);
399
+ }
470
400
  });
471
401
  }
402
+ const renderResult = yield this.handleWeb(context, route);
403
+ if (!renderResult) {
404
+ this.render404(context);
405
+ return;
406
+ }
407
+ if (renderResult.redirect) {
408
+ this.redirect(
409
+ res,
410
+ renderResult.content,
411
+ renderResult.statusCode
412
+ );
413
+ return;
414
+ }
472
415
  if (this.isSend(res)) {
473
416
  return;
474
417
  }
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);
418
+ res.setHeader("content-type", renderResult.contentType);
419
+ const { contentStream } = renderResult;
420
+ if (contentStream) {
421
+ contentStream.pipe(
422
+ (0, import_template.templateInjectableStream)({
423
+ prependHead: route.entryName ? `<script>window._SERVER_DATA=${JSON.stringify(
424
+ context.serverData
425
+ )}<\/script>` : void 0
426
+ })
427
+ ).pipe(res);
428
+ return;
429
+ }
430
+ let response = renderResult.content;
431
+ if (route.entryName) {
432
+ const afterRenderContext = (0, import_hook_api.createAfterRenderContext)(
433
+ context,
434
+ response.toString()
435
+ );
436
+ if (this.runMode === import_constants.RUN_MODE.FULL) {
437
+ yield this.runner.afterRender(afterRenderContext, { onLast: import_utils2.noop });
438
+ }
439
+ if (this.isSend(res)) {
440
+ return;
441
+ }
442
+ afterRenderContext.template.prependHead(
443
+ `<script>window._SERVER_DATA=${JSON.stringify(
444
+ context.serverData
445
+ )}<\/script>`
446
+ );
447
+ response = afterRenderContext.template.get();
448
+ }
449
+ res.end(response);
450
+ });
484
451
  }
485
452
  isSend(res) {
486
453
  if (res.headersSent) {
487
454
  return true;
488
455
  }
489
- if (res.getHeader('Location') && (0, _utils2.isRedirect)(res.statusCode)) {
456
+ if (res.getHeader("Location") && (0, import_utils2.isRedirect)(res.statusCode)) {
490
457
  res.end();
491
458
  return true;
492
459
  }
493
460
  return false;
494
461
  }
495
-
496
- // compose handlers and create the final handler
497
462
  compose() {
498
- const {
499
- handlers
500
- } = this;
463
+ const { handlers } = this;
501
464
  if (!Array.isArray(handlers)) {
502
- throw new TypeError('Middleware stack must be an array!');
465
+ throw new TypeError("Middleware stack must be an array!");
503
466
  }
504
467
  for (const fn of handlers) {
505
- if (typeof fn !== 'function') {
506
- throw new TypeError('Middleware must be composed of functions!');
468
+ if (typeof fn !== "function") {
469
+ throw new TypeError("Middleware must be composed of functions!");
507
470
  }
508
471
  }
509
472
  this._handler = (context, next) => {
510
473
  let i = 0;
511
- const dispatch = error => {
474
+ const dispatch = (error) => {
512
475
  if (error) {
513
476
  return this.onError(context, error);
514
477
  }
@@ -518,14 +481,13 @@ class ModernServer {
518
481
  }
519
482
  return handler(context, dispatch).catch(onError);
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,42 @@ 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;