@modern-js/prod-server 2.0.0-beta.2 → 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 +132 -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 -419
  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 -443
  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 -911
  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,471 +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 || {},
122
- // FIXME:
123
- this.conf.html);
124
- this.staticFileHandler = (0, _serveFile.createStaticFileHandler)([{
125
- path: staticPathRegExp,
126
- target: distDir
127
- }], this.conf.output);
128
- this.routeRenderHandler = (0, _render.createRenderHandler)({
129
- distDir,
130
- 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();
131
168
  });
132
- await this.setupBeforeProdMiddleware();
133
- this.addHandler(this.staticFileHandler);
134
-
135
- // execute after staticFileHandler, can rename to staticFallbackHandler if needed.
136
- this.addHandler(_serveFile.faviconFallbackHandler);
137
- this.addBeforeRouteHandler();
138
- this.addHandler(this.routeHandler.bind(this));
139
-
140
- // compose middlewares to http handler
141
- this.compose();
142
169
  }
143
-
144
- // server ready
145
170
  onRepack(_) {
146
- // empty
147
171
  }
148
172
  addBeforeRouteHandler() {
149
- this.addHandler(async (context, next) => {
173
+ this.addHandler((context, next) => __async(this, null, function* () {
150
174
  if (this.beforeRouteHandler) {
151
- await this.beforeRouteHandler(context);
175
+ yield this.beforeRouteHandler(context);
152
176
  if (this.isSend(context.res)) {
153
177
  return;
154
178
  }
155
179
  }
156
- // eslint-disable-next-line consistent-return
157
180
  return next();
158
- });
181
+ }));
159
182
  }
160
- onServerChange({
161
- filepath
162
- }) {
163
- const {
164
- pwd
165
- } = this;
166
- const {
167
- api,
168
- server
169
- } = _constants.AGGRED_DIR;
170
- const apiPath = _path.default.normalize(_path.default.join(pwd, api));
171
- 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));
172
188
  const onlyApi = filepath.startsWith(apiPath);
173
189
  const onlyWeb = filepath.startsWith(serverPath);
174
- this.prepareFrameHandler({
175
- onlyWeb,
176
- onlyApi
177
- });
190
+ this.prepareFrameHandler({ onlyWeb, onlyApi });
178
191
  }
179
-
180
- // exposed requestHandler
181
192
  getRequestHandler() {
182
193
  return this.requestHandler.bind(this);
183
194
  }
184
- async render(req, res, url) {
185
- req.logger = this.logger;
186
- req.metrics = this.metrics;
187
- const context = (0, _context.createContext)(req, res);
188
- const matched = this.router.match(url || context.path);
189
- if (!matched) {
190
- return null;
191
- }
192
- const route = matched.generate(context.url);
193
- const result = await this.handleWeb(context, route);
194
- if (!result) {
195
- return null;
196
- }
197
- 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
+ });
198
211
  }
199
- async createHTTPServer(handler) {
200
- return (0, _http.createServer)(handler);
212
+ createHTTPServer(handler) {
213
+ return __async(this, null, function* () {
214
+ return (0, import_http.createServer)(handler);
215
+ });
201
216
  }
202
-
203
- /* —————————————————————— function will be overwrite —————————————————————— */
204
- // get routes info
205
217
  getRoutes() {
206
- // Preferred to use preset routes
207
218
  if (this.presetRoutes) {
208
219
  return this.presetRoutes;
209
220
  }
210
-
211
- // read routes from spec file
212
- const file = _path.default.join(this.distDir, _utils.ROUTE_SPEC_FILE);
213
- if (_utils.fs.existsSync(file)) {
214
- 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);
215
224
  return content.routes;
216
225
  }
217
226
  return [];
218
227
  }
219
-
220
- // add promisify request handler to server
221
- // handler should do not do more things after invoke next
222
228
  addHandler(handler) {
223
- if (handler[Symbol.toStringTag] === 'AsyncFunction') {
229
+ if (handler[Symbol.toStringTag] === "AsyncFunction") {
224
230
  this.handlers.push(handler);
225
231
  } else {
226
- this.handlers.push(_util.default.promisify(handler));
232
+ this.handlers.push(import_util.default.promisify(handler));
227
233
  }
228
234
  }
229
-
230
- // return 404 page
231
235
  render404(context) {
232
- context.error(_constants.ERROR_DIGEST.ENOTF, '404 Not Found');
236
+ context.error(import_constants.ERROR_DIGEST.ENOTF, "404 Not Found");
233
237
  this.renderErrorPage(context, 404);
234
238
  }
235
- async prepareBeforeRouteHandler(specs, distDir) {
236
- const {
237
- runner
238
- } = this;
239
- const handler = await runner.preparebeforeRouteHandler({
240
- serverRoutes: specs,
241
- distDir
242
- }, {
243
- 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;
244
252
  });
245
- this.beforeRouteHandler = handler;
246
253
  }
247
-
248
- // gather frame extension and get framework handler
249
- async prepareFrameHandler(options) {
250
- const {
251
- workDir,
252
- runner
253
- } = this;
254
- const {
255
- onlyApi,
256
- onlyWeb
257
- } = options || {};
258
-
259
- // server hook, gather plugin inject
260
- const _createMiddlewareColl = (0, _utils2.createMiddlewareCollecter)(),
261
- {
262
- getMiddlewares
263
- } = _createMiddlewareColl,
264
- collector = _objectWithoutProperties(_createMiddlewareColl, _excluded);
265
- await runner.gather(collector);
266
- const {
267
- api: pluginAPIExt,
268
- web: pluginWebExt
269
- } = getMiddlewares();
270
- const apiDir = _path.default.join(workDir, API_DIR);
271
- const serverDir = _path.default.join(workDir, SERVER_DIR);
272
-
273
- // get api or web server handler from server-framework plugin
274
- if ((await _utils.fs.pathExists(_path.default.join(serverDir))) && !onlyApi) {
275
- const webExtension = (0, _utils2.mergeExtension)(pluginWebExt);
276
- this.frameWebHandler = await this.prepareWebHandler(webExtension);
277
- }
278
- if (_utils.fs.existsSync(apiDir) && !onlyWeb) {
279
- const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt);
280
- this.frameAPIHandler = await this.prepareAPIHandler(apiExtension);
281
- }
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
+ });
282
272
  }
283
- async prepareWebHandler(extension) {
284
- const {
285
- workDir,
286
- runner
287
- } = this;
288
- const handler = await runner.prepareWebServer({
289
- pwd: workDir,
290
- config: extension
291
- }, {
292
- 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;
293
284
  });
294
- return handler;
295
285
  }
296
- async prepareAPIHandler(extension) {
297
- const {
298
- workDir,
299
- runner,
300
- conf
301
- } = this;
302
- const {
303
- bff
304
- } = conf;
305
- const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || '/api';
306
- return runner.prepareApiServer({
307
- pwd: workDir,
308
- config: extension,
309
- prefix: Array.isArray(prefix) ? prefix[0] : prefix
310
- }, {
311
- 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
+ );
312
299
  });
313
300
  }
314
301
  filterRoutes(routes) {
315
302
  return routes;
316
303
  }
317
- async setupBeforeProdMiddleware() {
318
- const {
319
- conf,
320
- runner
321
- } = this;
322
- const preMiddleware = await runner.beforeProdServer(conf);
323
- preMiddleware.flat().forEach(mid => {
324
- 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
+ });
325
311
  });
326
312
  }
327
- async handleAPI(context) {
328
- const {
329
- req,
330
- res
331
- } = context;
332
- if (!this.frameAPIHandler) {
333
- throw new Error('can not found api handler');
334
- }
335
- 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
+ });
336
321
  }
337
- async handleWeb(context, route) {
338
- return this.routeRenderHandler({
339
- ctx: context,
340
- route,
341
- 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
+ });
342
329
  });
343
330
  }
344
- async proxy() {
345
- return null;
331
+ proxy() {
332
+ return __async(this, null, function* () {
333
+ return null;
334
+ });
346
335
  }
347
-
348
- // warmup ssr function
349
336
  warmupSSRBundle() {
350
- const {
351
- distDir
352
- } = this;
337
+ const { distDir } = this;
353
338
  const bundles = this.router.getBundles();
354
- bundles.forEach(bundle => {
355
- const filepath = _path.default.join(distDir, bundle);
356
- // if error, just throw and let process die
339
+ bundles.forEach((bundle) => {
340
+ const filepath = import_path.default.join(distDir, bundle);
357
341
  require(filepath);
358
342
  });
359
343
  }
360
344
  createContext(req, res, options = {}) {
361
- return (0, _context.createContext)(req, res, options);
345
+ return (0, import_context.createContext)(req, res, options);
362
346
  }
363
-
364
- /* —————————————————————— private function —————————————————————— */
365
- // handler route.json, include api / csr / ssr
366
- async routeHandler(context) {
367
- const {
368
- res
369
- } = context;
370
-
371
- // match routes in the route spec
372
- const matched = this.router.match(context.path);
373
- if (!matched) {
374
- this.render404(context);
375
- return;
376
- }
377
-
378
- // route is api service
379
- let route = matched.generate(context.url);
380
- if (route.isApi) {
381
- await this.handleAPI(context);
382
- return;
383
- }
384
- const afterMatchContext = (0, _hookApi.createAfterMatchContext)(context, route.entryName);
385
-
386
- // only full mode run server hook
387
- if (this.runMode === _constants.RUN_MODE.FULL) {
388
- await this.runner.afterMatch(afterMatchContext, {
389
- onLast: _utils2.noop
390
- });
391
- }
392
- if (this.isSend(res)) {
393
- return;
394
- }
395
- const {
396
- current,
397
- url,
398
- status
399
- } = afterMatchContext.router;
400
- // redirect to another url
401
- if (url) {
402
- this.redirect(res, url, status);
403
- return;
404
- }
405
-
406
- // rewrite to another entry
407
- if (route.entryName !== current) {
408
- 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);
409
351
  if (!matched) {
410
352
  this.render404(context);
411
353
  return;
412
354
  }
413
- route = matched.generate(context.url);
414
- }
415
- context.setParams(route.params);
416
- context.setServerData('router', {
417
- baseUrl: route.urlPath,
418
- params: route.params
419
- });
420
- if (this.frameWebHandler) {
421
- res.locals = res.locals || {};
422
- const middlewareContext = (0, _hookApi.createMiddlewareContext)(context);
423
- await this.frameWebHandler(middlewareContext);
424
- res.locals = _objectSpread(_objectSpread({}, res.locals), middlewareContext.response.locals);
425
- }
426
-
427
- // frameWebHandler has process request
428
- if (this.isSend(res)) {
429
- return;
430
- }
431
- if (route.responseHeaders) {
432
- Object.keys(route.responseHeaders).forEach(key => {
433
- const value = route.responseHeaders[key];
434
- if (value) {
435
- 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;
436
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
437
384
  });
438
- }
439
- const renderResult = await this.handleWeb(context, route);
440
- if (!renderResult) {
441
- this.render404(context);
442
- return;
443
- }
444
-
445
- // React Router navigation
446
- if (renderResult.redirect) {
447
- this.redirect(res, renderResult.content, renderResult.statusCode);
448
- return;
449
- }
450
- if (this.isSend(res)) {
451
- return;
452
- }
453
- res.setHeader('content-type', renderResult.contentType);
454
- const {
455
- contentStream
456
- } = renderResult;
457
- if (contentStream) {
458
- contentStream.pipe((0, _template.templateInjectableStream)({
459
- prependHead: route.entryName ? `<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>` : undefined
460
- })).pipe(res);
461
- return;
462
- }
463
- let response = renderResult.content;
464
- if (route.entryName) {
465
- const afterRenderContext = (0, _hookApi.createAfterRenderContext)(context, response.toString());
466
-
467
- // only full mode run server hook
468
- // FIXME: how to run server hook in streaming
469
- if (this.runMode === _constants.RUN_MODE.FULL) {
470
- await this.runner.afterRender(afterRenderContext, {
471
- 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
+ }
472
400
  });
473
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
+ }
474
415
  if (this.isSend(res)) {
475
416
  return;
476
417
  }
477
-
478
- // It will inject _SERVER_DATA twice, when SSG mode.
479
- // The first time was in ssg html created, the seoncd time was in prod-server start.
480
- // but the second wound causes route error.
481
- // To ensure that the second injection fails, the _SERVER_DATA inject at the front of head,
482
- afterRenderContext.template.prependHead(`<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>`);
483
- response = afterRenderContext.template.get();
484
- }
485
- 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
+ });
486
451
  }
487
452
  isSend(res) {
488
453
  if (res.headersSent) {
489
454
  return true;
490
455
  }
491
- if (res.getHeader('Location') && (0, _utils2.isRedirect)(res.statusCode)) {
456
+ if (res.getHeader("Location") && (0, import_utils2.isRedirect)(res.statusCode)) {
492
457
  res.end();
493
458
  return true;
494
459
  }
495
460
  return false;
496
461
  }
497
-
498
- // compose handlers and create the final handler
499
462
  compose() {
500
- const {
501
- handlers
502
- } = this;
463
+ const { handlers } = this;
503
464
  if (!Array.isArray(handlers)) {
504
- throw new TypeError('Middleware stack must be an array!');
465
+ throw new TypeError("Middleware stack must be an array!");
505
466
  }
506
467
  for (const fn of handlers) {
507
- if (typeof fn !== 'function') {
508
- throw new TypeError('Middleware must be composed of functions!');
468
+ if (typeof fn !== "function") {
469
+ throw new TypeError("Middleware must be composed of functions!");
509
470
  }
510
471
  }
511
472
  this._handler = (context, next) => {
512
473
  let i = 0;
513
- const dispatch = error => {
474
+ const dispatch = (error) => {
514
475
  if (error) {
515
476
  return this.onError(context, error);
516
477
  }
@@ -520,14 +481,13 @@ class ModernServer {
520
481
  }
521
482
  return handler(context, dispatch).catch(onError);
522
483
  };
523
- const onError = err => {
484
+ const onError = (err) => {
524
485
  this.onError(context, err);
525
486
  };
526
487
  return dispatch();
527
488
  };
528
489
  }
529
490
  requestHandler(req, res, next = () => {
530
- // empty
531
491
  }) {
532
492
  res.statusCode = 200;
533
493
  req.logger = this.logger;
@@ -538,8 +498,8 @@ class ModernServer {
538
498
  } catch (e) {
539
499
  this.logger.error(e);
540
500
  res.statusCode = 500;
541
- res.setHeader('content-type', _utils.mime.contentType('html'));
542
- 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]));
543
503
  }
544
504
  try {
545
505
  return this._handler(context, next);
@@ -548,50 +508,42 @@ class ModernServer {
548
508
  }
549
509
  }
550
510
  redirect(res, url, status = 302) {
551
- res.setHeader('Location', url);
511
+ res.setHeader("Location", url);
552
512
  res.statusCode = status;
553
513
  res.end();
554
514
  }
555
515
  onError(context, err) {
556
- context.error(_constants.ERROR_DIGEST.EINTER, err);
516
+ context.error(import_constants.ERROR_DIGEST.EINTER, err);
557
517
  this.renderErrorPage(context, 500);
558
518
  }
559
- async renderErrorPage(context, status) {
560
- const {
561
- res
562
- } = context;
563
- context.status = status;
564
- res.setHeader('content-type', _utils.mime.contentType('html'));
565
- const statusPage = `/${status}`;
566
- const customErrorPage = `/_error`;
567
- const matched = this.router.match(statusPage) || this.router.match(customErrorPage);
568
- // if no custom status page find
569
-
570
- if (matched) {
571
- const route = matched.generate(context.url);
572
- const {
573
- entryName
574
- } = route;
575
- // check entryName, avoid matched '/' route
576
- if (entryName === status.toString() || entryName === '_error') {
577
- try {
578
- const file = await this.routeRenderHandler({
579
- route,
580
- ctx: context,
581
- runner: this.runner
582
- });
583
- if (file) {
584
- context.res.end(file.content);
585
- 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) {
586
542
  }
587
- } catch (e) {
588
- // just catch error when the rendering error occurred in the custom error page.
589
543
  }
590
544
  }
591
- }
592
- const text = _constants.ERROR_PAGE_TEXT[status] || _constants.ERROR_PAGE_TEXT[500];
593
- 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
+ });
594
548
  }
595
549
  }
596
- /* eslint-enable max-lines */
597
- exports.ModernServer = ModernServer;