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