@modern-js/server 0.0.0-plugins-202111301002 → 0.0.0-runtime-2021112193858
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 +59 -0
- package/dist/js/modern/dev-tools/babel/register.js +2 -2
- package/dist/js/modern/dev-tools/mock/getMockData.js +2 -2
- package/dist/js/modern/libs/context/context.js +15 -7
- package/dist/js/modern/libs/context/index.js +2 -2
- package/dist/js/modern/libs/hook-api/route.js +37 -0
- package/dist/js/modern/libs/{hook-api.js → hook-api/template.js} +0 -0
- package/dist/js/modern/libs/{measure.js → metrics.js} +2 -2
- package/dist/js/modern/libs/proxy.js +2 -2
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +2 -2
- package/dist/js/modern/libs/render/cache/index.js +2 -2
- package/dist/js/modern/libs/render/ssr.js +1 -1
- package/dist/js/modern/libs/route/index.js +4 -0
- package/dist/js/modern/libs/route/matcher.js +4 -0
- package/dist/js/modern/libs/route/route.js +1 -1
- package/dist/js/modern/server/dev-server/dev-server-split.js +28 -0
- package/dist/js/modern/server/{dev-server.js → dev-server/dev-server.js} +41 -22
- package/dist/js/modern/server/dev-server/index.js +2 -0
- package/dist/js/modern/server/index.js +65 -63
- package/dist/js/modern/server/modern-server-split.js +81 -0
- package/dist/js/modern/server/modern-server.js +121 -70
- package/dist/js/modern/utils.js +11 -3
- package/dist/js/node/dev-tools/babel/register.js +2 -2
- package/dist/js/node/dev-tools/mock/getMockData.js +2 -2
- package/dist/js/node/libs/context/context.js +15 -7
- package/dist/js/node/libs/context/index.js +2 -2
- package/dist/js/node/libs/hook-api/route.js +46 -0
- package/dist/js/node/libs/{hook-api.js → hook-api/template.js} +0 -0
- package/dist/js/node/libs/{measure.js → metrics.js} +3 -3
- package/dist/js/node/libs/proxy.js +2 -2
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +2 -2
- package/dist/js/node/libs/render/cache/index.js +2 -2
- package/dist/js/node/libs/render/ssr.js +1 -1
- package/dist/js/node/libs/route/index.js +4 -0
- package/dist/js/node/libs/route/matcher.js +4 -0
- package/dist/js/node/libs/route/route.js +1 -1
- package/dist/js/node/server/dev-server/dev-server-split.js +41 -0
- package/dist/js/node/server/{dev-server.js → dev-server/dev-server.js} +42 -21
- package/dist/js/node/server/dev-server/index.js +27 -0
- package/dist/js/node/server/index.js +72 -64
- package/dist/js/node/server/modern-server-split.js +97 -0
- package/dist/js/node/server/modern-server.js +124 -71
- package/dist/js/node/utils.js +14 -4
- package/dist/types/libs/context/context.d.ts +5 -5
- package/dist/types/libs/context/index.d.ts +3 -3
- package/dist/types/libs/hook-api/route.d.ts +13 -0
- package/dist/types/libs/{hook-api.d.ts → hook-api/template.d.ts} +0 -0
- package/dist/types/libs/metrics.d.ts +3 -0
- package/dist/types/libs/render/type.d.ts +2 -2
- package/dist/types/libs/route/index.d.ts +1 -0
- package/dist/types/libs/route/matcher.d.ts +1 -0
- package/dist/types/libs/route/route.d.ts +2 -10
- package/dist/types/server/dev-server/dev-server-split.d.ts +15 -0
- package/dist/types/server/{dev-server.d.ts → dev-server/dev-server.d.ts} +6 -5
- package/dist/types/server/dev-server/index.d.ts +2 -0
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/modern-server-split.d.ts +26 -0
- package/dist/types/server/modern-server.d.ts +20 -12
- package/dist/types/type.d.ts +9 -4
- package/dist/types/utils.d.ts +3 -2
- package/package.json +18 -20
- package/src/libs/context/context.ts +12 -8
- package/src/libs/context/index.ts +3 -3
- package/src/libs/hook-api/route.ts +38 -0
- package/src/libs/{hook-api.ts → hook-api/template.ts} +0 -0
- package/src/libs/{measure.ts → metrics.ts} +3 -3
- package/src/libs/render/ssr.ts +1 -1
- package/src/libs/render/type.ts +2 -2
- package/src/libs/route/index.ts +4 -0
- package/src/libs/route/matcher.ts +4 -0
- package/src/libs/route/route.ts +4 -20
- package/src/server/{web-server.ts → dev-server/dev-server-split.ts} +12 -14
- package/src/server/{dev-server.ts → dev-server/dev-server.ts} +62 -33
- package/src/server/dev-server/index.ts +2 -0
- package/src/server/index.ts +81 -48
- package/src/server/modern-server-split.ts +97 -0
- package/src/server/modern-server.ts +140 -90
- package/src/type.ts +9 -4
- package/src/utils.ts +16 -2
- package/dist/js/modern/server/api-server.js +0 -36
- package/dist/js/modern/server/web-server.js +0 -30
- package/dist/js/node/server/api-server.js +0 -50
- package/dist/js/node/server/web-server.js +0 -44
- package/dist/types/libs/measure.d.ts +0 -3
- package/dist/types/server/api-server.d.ts +0 -17
- package/dist/types/server/web-server.d.ts +0 -15
- package/src/server/api-server.ts +0 -47
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ModernServer = void 0;
|
|
7
7
|
|
|
8
|
+
var _http = require("http");
|
|
9
|
+
|
|
8
10
|
var _util = _interopRequireDefault(require("util"));
|
|
9
11
|
|
|
10
12
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -33,7 +35,9 @@ var _context = require("../libs/context");
|
|
|
33
35
|
|
|
34
36
|
var _constants = require("../constants");
|
|
35
37
|
|
|
36
|
-
var
|
|
38
|
+
var _template = require("../libs/hook-api/template");
|
|
39
|
+
|
|
40
|
+
var _route2 = require("../libs/hook-api/route");
|
|
37
41
|
|
|
38
42
|
const _excluded = ["getMiddlewares"];
|
|
39
43
|
|
|
@@ -43,9 +47,9 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
43
47
|
|
|
44
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
49
|
|
|
46
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
50
|
+
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; }
|
|
47
51
|
|
|
48
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
52
|
+
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; }
|
|
49
53
|
|
|
50
54
|
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; }
|
|
51
55
|
|
|
@@ -67,8 +71,9 @@ class ModernServer {
|
|
|
67
71
|
routes,
|
|
68
72
|
staticGenerate,
|
|
69
73
|
logger,
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
metrics,
|
|
75
|
+
proxyTarget
|
|
76
|
+
}) {
|
|
72
77
|
this.pwd = void 0;
|
|
73
78
|
this.distDir = void 0;
|
|
74
79
|
this.workDir = void 0;
|
|
@@ -76,9 +81,10 @@ class ModernServer {
|
|
|
76
81
|
this.conf = void 0;
|
|
77
82
|
this.handlers = [];
|
|
78
83
|
this.presetRoutes = void 0;
|
|
79
|
-
this.logger = void 0;
|
|
80
|
-
this.measure = void 0;
|
|
81
84
|
this.runner = void 0;
|
|
85
|
+
this.logger = void 0;
|
|
86
|
+
this.metrics = void 0;
|
|
87
|
+
this.proxyTarget = void 0;
|
|
82
88
|
this.isDev = false;
|
|
83
89
|
this.staticFileHandler = void 0;
|
|
84
90
|
this.routeRenderHandler = void 0;
|
|
@@ -92,14 +98,14 @@ class ModernServer {
|
|
|
92
98
|
|
|
93
99
|
this.isDev = Boolean(dev);
|
|
94
100
|
this.pwd = pwd;
|
|
95
|
-
this.distDir = _path.default.join(pwd, config.output.path || '');
|
|
101
|
+
this.distDir = _path.default.join(pwd, config.output.path || 'dist');
|
|
96
102
|
this.workDir = this.isDev ? pwd : this.distDir;
|
|
97
103
|
this.conf = config;
|
|
98
|
-
this.runner = runner;
|
|
99
104
|
this.logger = logger;
|
|
100
|
-
this.
|
|
105
|
+
this.metrics = metrics;
|
|
101
106
|
this.router = new _route.RouteMatchManager();
|
|
102
107
|
this.presetRoutes = routes;
|
|
108
|
+
this.proxyTarget = proxyTarget;
|
|
103
109
|
|
|
104
110
|
if (staticGenerate) {
|
|
105
111
|
this.staticGenerate = staticGenerate;
|
|
@@ -114,9 +120,10 @@ class ModernServer {
|
|
|
114
120
|
} // server prepare
|
|
115
121
|
|
|
116
122
|
|
|
117
|
-
async init() {
|
|
123
|
+
async init(runner) {
|
|
118
124
|
var _conf$bff;
|
|
119
125
|
|
|
126
|
+
this.runner = runner;
|
|
120
127
|
const {
|
|
121
128
|
distDir,
|
|
122
129
|
isDev,
|
|
@@ -181,20 +188,10 @@ class ModernServer {
|
|
|
181
188
|
|
|
182
189
|
close() {
|
|
183
190
|
reader.close();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
warmupSSRBundle() {
|
|
188
|
-
const {
|
|
189
|
-
distDir
|
|
190
|
-
} = this;
|
|
191
|
-
const bundles = this.router.getBundles();
|
|
192
|
-
bundles.forEach(bundle => {
|
|
193
|
-
const filepath = _path.default.join(distDir, bundle); // if error, just throw and let process die
|
|
194
|
-
|
|
191
|
+
}
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
async createHTTPServer(handler) {
|
|
194
|
+
return (0, _http.createServer)(handler);
|
|
198
195
|
} // read route spec from route.json
|
|
199
196
|
|
|
200
197
|
|
|
@@ -229,20 +226,8 @@ class ModernServer {
|
|
|
229
226
|
async prepareFrameHandler() {
|
|
230
227
|
const {
|
|
231
228
|
workDir,
|
|
232
|
-
runner
|
|
233
|
-
|
|
234
|
-
} = this; // inner tool, gather user inject
|
|
235
|
-
|
|
236
|
-
let userAPIExt = [];
|
|
237
|
-
let userWebExt = [];
|
|
238
|
-
|
|
239
|
-
if (!conf.server.disableUserExtension) {
|
|
240
|
-
({
|
|
241
|
-
api: userAPIExt,
|
|
242
|
-
web: userWebExt
|
|
243
|
-
} = (0, _serverUtils.gather)(workDir));
|
|
244
|
-
} // server hook, gather plugin inject
|
|
245
|
-
|
|
229
|
+
runner
|
|
230
|
+
} = this; // server hook, gather plugin inject
|
|
246
231
|
|
|
247
232
|
const _createMiddlewareColl = (0, _serverUtils.createMiddlewareCollecter)(),
|
|
248
233
|
{
|
|
@@ -262,16 +247,21 @@ class ModernServer {
|
|
|
262
247
|
|
|
263
248
|
|
|
264
249
|
if (await _utils.fs.pathExists(_path.default.join(serverDir))) {
|
|
265
|
-
const webExtension = (0, _utils2.mergeExtension)(pluginWebExt
|
|
250
|
+
const webExtension = (0, _utils2.mergeExtension)(pluginWebExt);
|
|
266
251
|
this.frameWebHandler = await this.prepareWebHandler(webExtension);
|
|
267
252
|
}
|
|
268
253
|
|
|
269
254
|
if (_utils.fs.existsSync(apiDir)) {
|
|
270
255
|
const mode = _utils.fs.existsSync(_path.default.join(apiDir, _constants.AGGRED_DIR.lambda)) ? _constants.ApiServerMode.frame : _constants.ApiServerMode.func; // if use lambda/, mean framework style of writing, then discard user extension
|
|
271
256
|
|
|
272
|
-
const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt
|
|
257
|
+
const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt);
|
|
273
258
|
this.frameAPIHandler = await this.prepareAPIHandler(mode, apiExtension);
|
|
274
259
|
}
|
|
260
|
+
} // Todo
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async proxy() {
|
|
264
|
+
return null;
|
|
275
265
|
}
|
|
276
266
|
/* —————————————————————— function will be overwrite —————————————————————— */
|
|
277
267
|
|
|
@@ -303,7 +293,7 @@ class ModernServer {
|
|
|
303
293
|
pwd: workDir,
|
|
304
294
|
mode,
|
|
305
295
|
config: extension,
|
|
306
|
-
prefix
|
|
296
|
+
prefix: Array.isArray(prefix) ? prefix[0] : prefix
|
|
307
297
|
}, {
|
|
308
298
|
onLast: () => null
|
|
309
299
|
});
|
|
@@ -313,34 +303,55 @@ class ModernServer {
|
|
|
313
303
|
return routes;
|
|
314
304
|
}
|
|
315
305
|
|
|
306
|
+
async emitRouteHook(eventName, input) {
|
|
307
|
+
return this.runner[eventName](input, {
|
|
308
|
+
onLast: _utils2.noop
|
|
309
|
+
});
|
|
310
|
+
} // warmup ssr function
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
warmupSSRBundle() {
|
|
314
|
+
const {
|
|
315
|
+
distDir
|
|
316
|
+
} = this;
|
|
317
|
+
const bundles = this.router.getBundles();
|
|
318
|
+
bundles.forEach(bundle => {
|
|
319
|
+
const filepath = _path.default.join(distDir, bundle); // if error, just throw and let process die
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
require(filepath);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
316
326
|
async preServerInit() {
|
|
317
327
|
const {
|
|
318
|
-
conf
|
|
328
|
+
conf,
|
|
329
|
+
runner
|
|
319
330
|
} = this;
|
|
320
|
-
const preMiddleware = await
|
|
321
|
-
preMiddleware.forEach(mid => {
|
|
331
|
+
const preMiddleware = await runner.preServerInit(conf);
|
|
332
|
+
preMiddleware.flat().forEach(mid => {
|
|
322
333
|
this.addHandler(mid);
|
|
323
334
|
});
|
|
324
335
|
}
|
|
325
336
|
|
|
326
|
-
|
|
327
|
-
const
|
|
337
|
+
async handleAPI(context) {
|
|
338
|
+
const {
|
|
339
|
+
req,
|
|
340
|
+
res
|
|
341
|
+
} = context;
|
|
328
342
|
|
|
329
|
-
if (
|
|
330
|
-
|
|
343
|
+
if (!this.frameAPIHandler) {
|
|
344
|
+
throw new Error('can not found api hanlder');
|
|
331
345
|
}
|
|
332
346
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const curFavicon = faviconByEntries[f];
|
|
347
|
+
await this.frameAPIHandler(req, res);
|
|
348
|
+
}
|
|
336
349
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
});
|
|
341
|
-
}
|
|
350
|
+
async handleWeb(context, route) {
|
|
351
|
+
return this.routeRenderHandler(context, route);
|
|
352
|
+
}
|
|
342
353
|
|
|
343
|
-
|
|
354
|
+
verifyMatch(_c, _m) {// empty
|
|
344
355
|
}
|
|
345
356
|
/* —————————————————————— private function —————————————————————— */
|
|
346
357
|
// handler route.json, include api / csr / ssr
|
|
@@ -351,25 +362,43 @@ class ModernServer {
|
|
|
351
362
|
const {
|
|
352
363
|
req,
|
|
353
364
|
res
|
|
354
|
-
} = context;
|
|
365
|
+
} = context;
|
|
366
|
+
await this.emitRouteHook('beforeMatch', {
|
|
367
|
+
context
|
|
368
|
+
}); // match routes in the route spec
|
|
355
369
|
|
|
356
370
|
const matched = this.router.match(context.url);
|
|
357
371
|
|
|
358
372
|
if (!matched) {
|
|
359
373
|
this.render404(context);
|
|
360
374
|
return;
|
|
375
|
+
} else {
|
|
376
|
+
this.verifyMatch(context, matched);
|
|
361
377
|
}
|
|
362
378
|
|
|
363
|
-
|
|
364
|
-
|
|
379
|
+
if (res.headersSent) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const routeAPI = (0, _route2.createRouteAPI)(matched, this.router);
|
|
384
|
+
await this.emitRouteHook('afterMatch', {
|
|
385
|
+
context,
|
|
386
|
+
routeAPI
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
if (res.headersSent) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const {
|
|
394
|
+
current
|
|
395
|
+
} = routeAPI;
|
|
396
|
+
const route = current.generate();
|
|
397
|
+
const params = current.parseURLParams(context.url);
|
|
365
398
|
context.setParams(params); // route is api service
|
|
366
399
|
|
|
367
400
|
if (route.isApi) {
|
|
368
|
-
|
|
369
|
-
throw new Error('can not found api hanlder');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
await this.frameAPIHandler(req, res);
|
|
401
|
+
this.handleAPI(context);
|
|
373
402
|
return;
|
|
374
403
|
}
|
|
375
404
|
|
|
@@ -382,7 +411,13 @@ class ModernServer {
|
|
|
382
411
|
return;
|
|
383
412
|
}
|
|
384
413
|
|
|
385
|
-
|
|
414
|
+
if (route.entryName) {
|
|
415
|
+
await this.emitRouteHook('beforeRender', {
|
|
416
|
+
context
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const file = await this.handleWeb(context, route);
|
|
386
421
|
|
|
387
422
|
if (!file) {
|
|
388
423
|
this.render404(context);
|
|
@@ -399,12 +434,10 @@ class ModernServer {
|
|
|
399
434
|
let response = file.content;
|
|
400
435
|
|
|
401
436
|
if (route.entryName) {
|
|
402
|
-
const templateAPI = (0,
|
|
403
|
-
await this.
|
|
437
|
+
const templateAPI = (0, _template.createTemplateAPI)(file.content.toString());
|
|
438
|
+
await this.emitRouteHook('afterRender', {
|
|
404
439
|
context,
|
|
405
440
|
templateAPI
|
|
406
|
-
}, {
|
|
407
|
-
onLast: _utils2.noop
|
|
408
441
|
});
|
|
409
442
|
await this.injectMicroFE(context, templateAPI);
|
|
410
443
|
response = templateAPI.get();
|
|
@@ -524,7 +557,7 @@ class ModernServer {
|
|
|
524
557
|
res.statusCode = 200;
|
|
525
558
|
const context = (0, _context.createContext)(req, res, {
|
|
526
559
|
logger: this.logger,
|
|
527
|
-
|
|
560
|
+
metrics: this.metrics
|
|
528
561
|
});
|
|
529
562
|
|
|
530
563
|
try {
|
|
@@ -572,6 +605,26 @@ class ModernServer {
|
|
|
572
605
|
res.end((0, _utils2.createErrorDocument)(status, text));
|
|
573
606
|
}
|
|
574
607
|
|
|
608
|
+
prepareFavicons(favicon, faviconByEntries) {
|
|
609
|
+
const faviconNames = [];
|
|
610
|
+
|
|
611
|
+
if (favicon) {
|
|
612
|
+
faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (faviconByEntries) {
|
|
616
|
+
Object.keys(faviconByEntries).forEach(f => {
|
|
617
|
+
const curFavicon = faviconByEntries[f];
|
|
618
|
+
|
|
619
|
+
if (curFavicon) {
|
|
620
|
+
faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return faviconNames;
|
|
626
|
+
}
|
|
627
|
+
|
|
575
628
|
}
|
|
576
629
|
/* eslint-enable max-lines */
|
|
577
630
|
|
package/dist/js/node/utils.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.applyMixins = applyMixins;
|
|
6
7
|
exports.toMessage = exports.noop = exports.mergeExtension = exports.createErrorDocument = void 0;
|
|
7
8
|
|
|
8
|
-
const mergeExtension =
|
|
9
|
+
const mergeExtension = users => {
|
|
9
10
|
const output = [];
|
|
10
11
|
return {
|
|
11
|
-
middleware: output.concat(users)
|
|
12
|
+
middleware: output.concat(users)
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
15
|
|
|
@@ -63,6 +64,15 @@ const createErrorDocument = (status, text) => {
|
|
|
63
64
|
</body>
|
|
64
65
|
</html>
|
|
65
66
|
`;
|
|
66
|
-
};
|
|
67
|
+
}; // This can live anywhere in your codebase:
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
exports.createErrorDocument = createErrorDocument;
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
function applyMixins(derivedCtor, constructors) {
|
|
73
|
+
constructors.forEach(baseCtor => {
|
|
74
|
+
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
|
75
|
+
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import { URL } from 'url';
|
|
4
4
|
import qs from 'querystring';
|
|
5
|
-
import type { ModernServerContext as ModernServerContextInterface,
|
|
5
|
+
import type { ModernServerContext as ModernServerContextInterface, Metrics, Logger } from '@modern-js/types/server';
|
|
6
6
|
export declare class ModernServerContext implements ModernServerContextInterface {
|
|
7
7
|
/**
|
|
8
8
|
* http request
|
|
@@ -19,18 +19,18 @@ export declare class ModernServerContext implements ModernServerContextInterface
|
|
|
19
19
|
|
|
20
20
|
params: Record<string, string>;
|
|
21
21
|
logger: Logger;
|
|
22
|
-
|
|
22
|
+
metrics?: Metrics;
|
|
23
23
|
constructor(req: IncomingMessage, res: ServerResponse, {
|
|
24
24
|
logger,
|
|
25
|
-
|
|
25
|
+
metrics
|
|
26
26
|
}: {
|
|
27
27
|
logger: Logger;
|
|
28
|
-
|
|
28
|
+
metrics: Metrics;
|
|
29
29
|
});
|
|
30
|
+
private bind;
|
|
30
31
|
setParams(params: Record<string, string>): void;
|
|
31
32
|
getReqHeader(key: string): string | string[];
|
|
32
33
|
get headers(): import("http").IncomingHttpHeaders;
|
|
33
|
-
set headers(val: import("http").IncomingHttpHeaders);
|
|
34
34
|
get method(): string;
|
|
35
35
|
get url(): string;
|
|
36
36
|
set url(val: string);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
-
import {
|
|
2
|
+
import { Metrics, Logger } from '../../type';
|
|
3
3
|
import { ModernServerContext } from './context';
|
|
4
4
|
export declare const createContext: (req: IncomingMessage, res: ServerResponse, {
|
|
5
5
|
logger,
|
|
6
|
-
|
|
6
|
+
metrics
|
|
7
7
|
}: {
|
|
8
8
|
logger: Logger;
|
|
9
|
-
|
|
9
|
+
metrics: Metrics;
|
|
10
10
|
}) => ModernServerContext;
|
|
11
11
|
export { ModernServerContext };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RouteMatchManager, RouteMatcher } from '../route';
|
|
2
|
+
|
|
3
|
+
declare class RouteAPI {
|
|
4
|
+
private readonly router;
|
|
5
|
+
private current;
|
|
6
|
+
constructor(matched: RouteMatcher, router: RouteMatchManager);
|
|
7
|
+
cur(): import("../route").ModernRoute;
|
|
8
|
+
get(entryName: string): import("../route").ModernRoute | null;
|
|
9
|
+
use(entryName: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const createRouteAPI: (matched: RouteMatcher, router: RouteMatchManager) => RouteAPI;
|
|
13
|
+
export {};
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="react" />
|
|
3
3
|
import { IncomingHttpHeaders } from 'http';
|
|
4
|
-
import {
|
|
4
|
+
import { Metrics, Logger } from '../../type';
|
|
5
5
|
declare type MetaKeyMap = {
|
|
6
6
|
header?: string[];
|
|
7
7
|
query?: string[];
|
|
@@ -40,7 +40,7 @@ export declare type SSRServerContext = {
|
|
|
40
40
|
template: string;
|
|
41
41
|
entryName: string;
|
|
42
42
|
logger: Logger;
|
|
43
|
-
|
|
43
|
+
metrics?: Metrics;
|
|
44
44
|
loadableManifest?: string;
|
|
45
45
|
cacheConfig?: CacheConfig;
|
|
46
46
|
staticGenerate?: boolean;
|
|
@@ -8,6 +8,7 @@ export declare class RouteMatchManager {
|
|
|
8
8
|
private best;
|
|
9
9
|
reset(specs: ModernRouteInterface[]): void;
|
|
10
10
|
match(pathname: string): RouteMatcher | undefined;
|
|
11
|
+
matchEntry(entryname: string): RouteMatcher | undefined;
|
|
11
12
|
getBundles(): (string | undefined)[];
|
|
12
13
|
}
|
|
13
14
|
export type { ModernRouteInterface, RouteMatcher, ModernRoute };
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
urlPath: string;
|
|
4
|
-
entryPath?: string;
|
|
5
|
-
isSPA?: boolean;
|
|
6
|
-
isSSR?: boolean;
|
|
7
|
-
isApi?: boolean;
|
|
8
|
-
bundle?: string;
|
|
9
|
-
enableModernMode?: boolean;
|
|
10
|
-
}
|
|
1
|
+
import { ServerRoute as ModernRouteInterface } from '@modern-js/types';
|
|
2
|
+
export type { ModernRouteInterface };
|
|
11
3
|
export declare class ModernRoute implements ModernRouteInterface {
|
|
12
4
|
entryName: string;
|
|
13
5
|
urlPath: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { APIServerStartInput } from '@modern-js/server-plugin';
|
|
2
|
+
import { ModernDevServer } from './dev-server';
|
|
3
|
+
import { mergeExtension } from "../../utils.d";
|
|
4
|
+
import { ModernRouteInterface } from "../../libs/route";
|
|
5
|
+
import { ApiServerMode } from "../../constants.d";
|
|
6
|
+
export declare class ModernSSRDevServer extends ModernDevServer {
|
|
7
|
+
protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
|
|
8
|
+
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
9
|
+
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
10
|
+
}
|
|
11
|
+
export declare class ModernAPIDevServer extends ModernDevServer {
|
|
12
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
13
|
+
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
14
|
+
protected preServerInit(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Server } from 'http';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import http, { Server, IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { ModernServer } from '../modern-server';
|
|
4
|
+
import { ModernServerOptions, ServerHookRunner, ReadyOptions } from "../../type.d";
|
|
5
5
|
export declare class ModernDevServer extends ModernServer {
|
|
6
6
|
private devProxyHandler;
|
|
7
7
|
private mockHandler;
|
|
@@ -10,11 +10,12 @@ export declare class ModernDevServer extends ModernServer {
|
|
|
10
10
|
private socketServer;
|
|
11
11
|
private watcher;
|
|
12
12
|
private devMiddleware;
|
|
13
|
-
constructor(options: ModernServerOptions
|
|
14
|
-
init(): Promise<void>;
|
|
13
|
+
constructor(options: ModernServerOptions);
|
|
14
|
+
init(runner: ServerHookRunner): Promise<void>;
|
|
15
15
|
ready(options?: ReadyOptions): void;
|
|
16
16
|
onListening(app: Server): void;
|
|
17
17
|
close(): Promise<void>;
|
|
18
|
+
createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<http.Server | import("https").Server>;
|
|
18
19
|
private setupCompiler;
|
|
19
20
|
private setupDevServerPlugin;
|
|
20
21
|
private setupHooks;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse, Server as httpServer } from 'http';
|
|
3
|
-
import { ModernServerOptions, ReadyOptions } from
|
|
3
|
+
import { ModernServerOptions, ReadyOptions } from "../type.d";
|
|
4
4
|
export declare class Server {
|
|
5
5
|
options: ModernServerOptions;
|
|
6
6
|
private server;
|
|
@@ -15,4 +15,6 @@ export declare class Server {
|
|
|
15
15
|
close(): Promise<void>;
|
|
16
16
|
private createProdServer;
|
|
17
17
|
private createDevServer;
|
|
18
|
+
private createHookRunner;
|
|
19
|
+
private initAppContext;
|
|
18
20
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { APIServerStartInput } from '@modern-js/server-plugin';
|
|
2
|
+
import { ModernServer } from './modern-server';
|
|
3
|
+
import { mergeExtension } from "../utils.d";
|
|
4
|
+
import { ModernRoute, ModernRouteInterface, RouteMatcher } from "../libs/route";
|
|
5
|
+
import { ApiServerMode } from "../constants.d";
|
|
6
|
+
import { ModernServerContext } from "../libs/context";
|
|
7
|
+
export declare class ModernSSRServer extends ModernServer {
|
|
8
|
+
protected warmupSSRBundle(): Promise<void>;
|
|
9
|
+
protected verifyMatch(context: ModernServerContext, matched: RouteMatcher): void;
|
|
10
|
+
protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
|
|
11
|
+
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
12
|
+
protected preServerInit(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ModernAPIServer extends ModernServer {
|
|
15
|
+
protected emitRouteHook(_: string, _input: any): Promise<void>;
|
|
16
|
+
protected warmupSSRBundle(): Promise<void>;
|
|
17
|
+
protected prepareWebHandler(_: ReturnType<typeof mergeExtension>): any;
|
|
18
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
19
|
+
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
20
|
+
protected preServerInit(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare class ModernWebServer extends ModernServer {
|
|
23
|
+
protected warmupSSRBundle(): Promise<void>;
|
|
24
|
+
protected handleAPI(context: ModernServerContext): Promise<void>;
|
|
25
|
+
protected handleWeb(context: ModernServerContext, route: ModernRoute): Promise<any>;
|
|
26
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
3
|
-
import { Adapter } from '@modern-js/server-plugin';
|
|
3
|
+
import { Adapter, APIServerStartInput } from '@modern-js/server-plugin';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
|
-
import { ModernServerOptions, NextFunction, ServerHookRunner,
|
|
6
|
-
import { RouteMatchManager, ModernRouteInterface } from
|
|
7
|
-
import { mergeExtension } from
|
|
5
|
+
import { ModernServerOptions, NextFunction, ServerHookRunner, Metrics, Logger, ReadyOptions } from "../type.d";
|
|
6
|
+
import { RouteMatchManager, ModernRouteInterface, ModernRoute, RouteMatcher } from "../libs/route";
|
|
7
|
+
import { mergeExtension } from "../utils.d";
|
|
8
8
|
import { ModernServerContext } from "../libs/context";
|
|
9
9
|
import { ApiServerMode } from "../constants.d";
|
|
10
10
|
declare type ModernServerHandler = (context: ModernServerContext, next: NextFunction) => Promise<void> | void;
|
|
@@ -17,9 +17,10 @@ export declare class ModernServer {
|
|
|
17
17
|
protected conf: NormalizedConfig;
|
|
18
18
|
protected handlers: ModernServerAsyncHandler[];
|
|
19
19
|
protected presetRoutes?: ModernRouteInterface[];
|
|
20
|
+
protected runner: ServerHookRunner;
|
|
20
21
|
protected readonly logger: Logger;
|
|
21
|
-
protected readonly
|
|
22
|
-
|
|
22
|
+
protected readonly metrics: Metrics;
|
|
23
|
+
protected readonly proxyTarget: ModernServerOptions['proxyTarget'];
|
|
23
24
|
private readonly isDev;
|
|
24
25
|
private staticFileHandler;
|
|
25
26
|
private routeRenderHandler;
|
|
@@ -35,28 +36,35 @@ export declare class ModernServer {
|
|
|
35
36
|
routes,
|
|
36
37
|
staticGenerate,
|
|
37
38
|
logger,
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
metrics,
|
|
40
|
+
proxyTarget
|
|
41
|
+
}: ModernServerOptions);
|
|
40
42
|
getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
|
|
41
|
-
init(): Promise<void>;
|
|
43
|
+
init(runner: ServerHookRunner): Promise<void>;
|
|
42
44
|
ready(_: ReadyOptions): void;
|
|
43
45
|
onListening(_: Server): void;
|
|
44
46
|
close(): void;
|
|
45
|
-
|
|
47
|
+
createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server>;
|
|
46
48
|
protected readRouteSpec(): ModernRouteInterface[];
|
|
47
49
|
protected addHandler(handler: ModernServerHandler): void;
|
|
48
50
|
protected render404(context: ModernServerContext): void;
|
|
49
51
|
protected prepareFrameHandler(): Promise<void>;
|
|
52
|
+
protected proxy(): Promise<any>;
|
|
50
53
|
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<Adapter>;
|
|
51
|
-
protected prepareAPIHandler(mode: ApiServerMode, extension:
|
|
54
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<Adapter>;
|
|
52
55
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
56
|
+
protected emitRouteHook(eventName: 'beforeMatch' | 'afterMatch' | 'beforeRender' | 'afterRender', input: any): Promise<any>;
|
|
57
|
+
protected warmupSSRBundle(): void;
|
|
53
58
|
protected preServerInit(): Promise<void>;
|
|
54
|
-
|
|
59
|
+
protected handleAPI(context: ModernServerContext): Promise<void>;
|
|
60
|
+
protected handleWeb(context: ModernServerContext, route: ModernRoute): Promise<import("@/type").RenderResult | null>;
|
|
61
|
+
protected verifyMatch(_c: ModernServerContext, _m: RouteMatcher): void;
|
|
55
62
|
private routeHandler;
|
|
56
63
|
private injectMicroFE;
|
|
57
64
|
private compose;
|
|
58
65
|
private requestHandler;
|
|
59
66
|
private onError;
|
|
60
67
|
private renderErrorPage;
|
|
68
|
+
private prepareFavicons;
|
|
61
69
|
}
|
|
62
70
|
export {};
|