@modern-js/server 1.1.3 → 1.1.4-rc.0
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 +23 -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/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/server/dev-server/dev-server-split.js +2 -6
- package/dist/js/modern/server/dev-server/index.js +1 -1
- package/dist/js/modern/server/index.js +15 -13
- package/dist/js/modern/server/modern-server-split.js +55 -6
- package/dist/js/modern/server/modern-server.js +84 -52
- package/dist/js/modern/utils.js +9 -1
- 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/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/server/dev-server/dev-server-split.js +5 -9
- package/dist/js/node/server/dev-server/index.js +4 -4
- package/dist/js/node/server/index.js +14 -12
- package/dist/js/node/server/modern-server-split.js +61 -9
- package/dist/js/node/server/modern-server.js +85 -53
- package/dist/js/node/utils.js +12 -2
- package/dist/types/server/dev-server/dev-server-split.d.ts +3 -4
- package/dist/types/server/dev-server/index.d.ts +1 -1
- package/dist/types/server/modern-server-split.d.ts +15 -5
- package/dist/types/server/modern-server.d.ts +13 -6
- package/dist/types/type.d.ts +5 -0
- package/dist/types/utils.d.ts +2 -1
- package/package.json +9 -8
- package/src/server/dev-server/dev-server-split.ts +3 -7
- package/src/server/dev-server/dev-server.ts +6 -10
- package/src/server/dev-server/index.ts +1 -1
- package/src/server/index.ts +19 -12
- package/src/server/modern-server-split.ts +59 -7
- package/src/server/modern-server.ts +95 -58
- package/src/type.ts +5 -0
- package/src/utils.ts +14 -0
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "ModernAPIDevServer", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return _devServerSplit.
|
|
9
|
+
return _devServerSplit.ModernAPIDevServer;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "ModernDevServer", {
|
|
@@ -15,10 +15,10 @@ Object.defineProperty(exports, "ModernDevServer", {
|
|
|
15
15
|
return _devServer.ModernDevServer;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "ModernSSRDevServer", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return _devServerSplit.
|
|
21
|
+
return _devServerSplit.ModernSSRDevServer;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -21,9 +21,9 @@ var _measure = require("../libs/measure");
|
|
|
21
21
|
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
|
|
24
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
24
|
+
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; }
|
|
25
25
|
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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
27
|
|
|
28
28
|
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; }
|
|
29
29
|
|
|
@@ -95,9 +95,11 @@ class Server {
|
|
|
95
95
|
} = this;
|
|
96
96
|
|
|
97
97
|
if (options.apiOnly) {
|
|
98
|
-
return new _modernServerSplit.
|
|
98
|
+
return new _modernServerSplit.ModernAPIServer(options);
|
|
99
|
+
} else if (options.ssrOnly) {
|
|
100
|
+
return new _modernServerSplit.ModernSSRServer(options);
|
|
99
101
|
} else if (options.webOnly) {
|
|
100
|
-
return new _modernServerSplit.
|
|
102
|
+
return new _modernServerSplit.ModernWebServer(options);
|
|
101
103
|
} else {
|
|
102
104
|
return new _modernServer.ModernServer(options);
|
|
103
105
|
}
|
|
@@ -109,15 +111,15 @@ class Server {
|
|
|
109
111
|
} = this;
|
|
110
112
|
|
|
111
113
|
const {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
ModernAPIDevServer,
|
|
115
|
+
ModernSSRDevServer,
|
|
114
116
|
ModernDevServer
|
|
115
117
|
} = require("./dev-server");
|
|
116
118
|
|
|
117
119
|
if (options.apiOnly) {
|
|
118
|
-
return new
|
|
119
|
-
} else if (options.
|
|
120
|
-
return new
|
|
120
|
+
return new ModernAPIDevServer(options);
|
|
121
|
+
} else if (options.ssrOnly) {
|
|
122
|
+
return new ModernSSRDevServer(options);
|
|
121
123
|
} else {
|
|
122
124
|
return new ModernDevServer(options);
|
|
123
125
|
}
|
|
@@ -129,6 +131,9 @@ class Server {
|
|
|
129
131
|
const {
|
|
130
132
|
options
|
|
131
133
|
} = this;
|
|
134
|
+
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
135
|
+
_serverPlugin.serverManager.usePlugin(p);
|
|
136
|
+
});
|
|
132
137
|
const appContext = await this.initAppContext();
|
|
133
138
|
|
|
134
139
|
_serverPlugin.serverManager.run(() => {
|
|
@@ -139,9 +144,6 @@ class Server {
|
|
|
139
144
|
}));
|
|
140
145
|
});
|
|
141
146
|
|
|
142
|
-
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
143
|
-
_serverPlugin.serverManager.usePlugin(p);
|
|
144
|
-
});
|
|
145
147
|
return _serverPlugin.serverManager.init({});
|
|
146
148
|
}
|
|
147
149
|
|
|
@@ -3,28 +3,46 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ModernWebServer = exports.ModernSSRServer = exports.ModernAPIServer = void 0;
|
|
7
7
|
|
|
8
8
|
var _modernServer = require("./modern-server");
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class ModernSSRServer extends _modernServer.ModernServer {
|
|
11
|
+
// Todo should not invoke any route hook in modernSSRServer
|
|
12
|
+
async warmupSSRBundle() {// empty
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
verifyMatch(context, matched) {
|
|
16
|
+
if (matched.generate().isApi) {
|
|
17
|
+
this.render404(context);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
prepareAPIHandler(_m, _) {
|
|
12
22
|
return null;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
async prepareWebHandler(extension) {
|
|
16
26
|
return super.prepareWebHandler(extension);
|
|
17
|
-
}
|
|
27
|
+
} // protected filterRoutes(routes: ModernRouteInterface[]) {
|
|
28
|
+
// return routes.filter(route => route.entryName);
|
|
29
|
+
// }
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
|
|
32
|
+
async preServerInit() {// empty
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
exports.
|
|
37
|
+
exports.ModernSSRServer = ModernSSRServer;
|
|
38
|
+
|
|
39
|
+
class ModernAPIServer extends _modernServer.ModernServer {
|
|
40
|
+
async emitRouteHook(_, _input) {// empty
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async warmupSSRBundle() {// empty
|
|
44
|
+
}
|
|
26
45
|
|
|
27
|
-
class APIModernServer extends _modernServer.ModernServer {
|
|
28
46
|
prepareWebHandler(_) {
|
|
29
47
|
return null;
|
|
30
48
|
}
|
|
@@ -37,9 +55,43 @@ class APIModernServer extends _modernServer.ModernServer {
|
|
|
37
55
|
return routes.filter(route => route.isApi);
|
|
38
56
|
}
|
|
39
57
|
|
|
40
|
-
async preServerInit() {//
|
|
58
|
+
async preServerInit() {// empty
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.ModernAPIServer = ModernAPIServer;
|
|
64
|
+
|
|
65
|
+
class ModernWebServer extends _modernServer.ModernServer {
|
|
66
|
+
async warmupSSRBundle() {// empty
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async handleAPI(context) {
|
|
70
|
+
const {
|
|
71
|
+
proxyTarget
|
|
72
|
+
} = this;
|
|
73
|
+
|
|
74
|
+
if (!(proxyTarget !== null && proxyTarget !== void 0 && proxyTarget.api)) {
|
|
75
|
+
this.proxy();
|
|
76
|
+
} else {
|
|
77
|
+
this.render404(context);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async handleWeb(context, route) {
|
|
82
|
+
const {
|
|
83
|
+
proxyTarget
|
|
84
|
+
} = this;
|
|
85
|
+
|
|
86
|
+
if (route.isSSR && proxyTarget !== null && proxyTarget !== void 0 && proxyTarget.ssr) {
|
|
87
|
+
return this.proxy();
|
|
88
|
+
} else {
|
|
89
|
+
// if no proxyTarget but access web server, degradation to csr
|
|
90
|
+
route.isSSR = false;
|
|
91
|
+
return super.handleWeb(context, route);
|
|
92
|
+
}
|
|
41
93
|
}
|
|
42
94
|
|
|
43
95
|
}
|
|
44
96
|
|
|
45
|
-
exports.
|
|
97
|
+
exports.ModernWebServer = ModernWebServer;
|
|
@@ -47,9 +47,9 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
47
47
|
|
|
48
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
49
|
|
|
50
|
-
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; }
|
|
51
51
|
|
|
52
|
-
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; }
|
|
53
53
|
|
|
54
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; }
|
|
55
55
|
|
|
@@ -71,7 +71,8 @@ class ModernServer {
|
|
|
71
71
|
routes,
|
|
72
72
|
staticGenerate,
|
|
73
73
|
logger,
|
|
74
|
-
measure
|
|
74
|
+
measure,
|
|
75
|
+
proxyTarget
|
|
75
76
|
}) {
|
|
76
77
|
this.pwd = void 0;
|
|
77
78
|
this.distDir = void 0;
|
|
@@ -83,6 +84,7 @@ class ModernServer {
|
|
|
83
84
|
this.runner = void 0;
|
|
84
85
|
this.logger = void 0;
|
|
85
86
|
this.measure = void 0;
|
|
87
|
+
this.proxyTarget = void 0;
|
|
86
88
|
this.isDev = false;
|
|
87
89
|
this.staticFileHandler = void 0;
|
|
88
90
|
this.routeRenderHandler = void 0;
|
|
@@ -96,13 +98,14 @@ class ModernServer {
|
|
|
96
98
|
|
|
97
99
|
this.isDev = Boolean(dev);
|
|
98
100
|
this.pwd = pwd;
|
|
99
|
-
this.distDir = _path.default.join(pwd, config.output.path || '');
|
|
101
|
+
this.distDir = _path.default.join(pwd, config.output.path || 'dist');
|
|
100
102
|
this.workDir = this.isDev ? pwd : this.distDir;
|
|
101
103
|
this.conf = config;
|
|
102
104
|
this.logger = logger;
|
|
103
105
|
this.measure = measure;
|
|
104
106
|
this.router = new _route.RouteMatchManager();
|
|
105
107
|
this.presetRoutes = routes;
|
|
108
|
+
this.proxyTarget = proxyTarget;
|
|
106
109
|
|
|
107
110
|
if (staticGenerate) {
|
|
108
111
|
this.staticGenerate = staticGenerate;
|
|
@@ -189,20 +192,6 @@ class ModernServer {
|
|
|
189
192
|
|
|
190
193
|
async createHTTPServer(handler) {
|
|
191
194
|
return (0, _http.createServer)(handler);
|
|
192
|
-
} // warmup ssr function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
warmupSSRBundle() {
|
|
196
|
-
const {
|
|
197
|
-
distDir
|
|
198
|
-
} = this;
|
|
199
|
-
const bundles = this.router.getBundles();
|
|
200
|
-
bundles.forEach(bundle => {
|
|
201
|
-
const filepath = _path.default.join(distDir, bundle); // if error, just throw and let process die
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
require(filepath);
|
|
205
|
-
});
|
|
206
195
|
} // read route spec from route.json
|
|
207
196
|
|
|
208
197
|
|
|
@@ -268,6 +257,11 @@ class ModernServer {
|
|
|
268
257
|
const apiExtension = (0, _utils2.mergeExtension)(pluginAPIExt);
|
|
269
258
|
this.frameAPIHandler = await this.prepareAPIHandler(mode, apiExtension);
|
|
270
259
|
}
|
|
260
|
+
} // Todo
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async proxy() {
|
|
264
|
+
return null;
|
|
271
265
|
}
|
|
272
266
|
/* —————————————————————— function will be overwrite —————————————————————— */
|
|
273
267
|
|
|
@@ -309,34 +303,55 @@ class ModernServer {
|
|
|
309
303
|
return routes;
|
|
310
304
|
}
|
|
311
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
|
+
|
|
312
326
|
async preServerInit() {
|
|
313
327
|
const {
|
|
314
|
-
conf
|
|
328
|
+
conf,
|
|
329
|
+
runner
|
|
315
330
|
} = this;
|
|
316
|
-
const preMiddleware = await
|
|
331
|
+
const preMiddleware = await runner.preServerInit(conf);
|
|
317
332
|
preMiddleware.flat().forEach(mid => {
|
|
318
333
|
this.addHandler(mid);
|
|
319
334
|
});
|
|
320
335
|
}
|
|
321
336
|
|
|
322
|
-
|
|
323
|
-
const
|
|
337
|
+
async handleAPI(context) {
|
|
338
|
+
const {
|
|
339
|
+
req,
|
|
340
|
+
res
|
|
341
|
+
} = context;
|
|
324
342
|
|
|
325
|
-
if (
|
|
326
|
-
|
|
343
|
+
if (!this.frameAPIHandler) {
|
|
344
|
+
throw new Error('can not found api hanlder');
|
|
327
345
|
}
|
|
328
346
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const curFavicon = faviconByEntries[f];
|
|
347
|
+
await this.frameAPIHandler(req, res);
|
|
348
|
+
}
|
|
332
349
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
});
|
|
337
|
-
}
|
|
350
|
+
async handleWeb(context, route) {
|
|
351
|
+
return this.routeRenderHandler(context, route);
|
|
352
|
+
}
|
|
338
353
|
|
|
339
|
-
|
|
354
|
+
verifyMatch(_c, _m) {// empty
|
|
340
355
|
}
|
|
341
356
|
/* —————————————————————— private function —————————————————————— */
|
|
342
357
|
// handler route.json, include api / csr / ssr
|
|
@@ -348,10 +363,8 @@ class ModernServer {
|
|
|
348
363
|
req,
|
|
349
364
|
res
|
|
350
365
|
} = context;
|
|
351
|
-
await this.
|
|
366
|
+
await this.emitRouteHook('beforeMatch', {
|
|
352
367
|
context
|
|
353
|
-
}, {
|
|
354
|
-
onLast: _utils2.noop
|
|
355
368
|
}); // match routes in the route spec
|
|
356
369
|
|
|
357
370
|
const matched = this.router.match(context.url);
|
|
@@ -359,14 +372,18 @@ class ModernServer {
|
|
|
359
372
|
if (!matched) {
|
|
360
373
|
this.render404(context);
|
|
361
374
|
return;
|
|
375
|
+
} else {
|
|
376
|
+
this.verifyMatch(context, matched);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (res.headersSent) {
|
|
380
|
+
return;
|
|
362
381
|
}
|
|
363
382
|
|
|
364
383
|
const routeAPI = (0, _route2.createRouteAPI)(matched, this.router);
|
|
365
|
-
await this.
|
|
384
|
+
await this.emitRouteHook('afterMatch', {
|
|
366
385
|
context,
|
|
367
386
|
routeAPI
|
|
368
|
-
}, {
|
|
369
|
-
onLast: _utils2.noop
|
|
370
387
|
});
|
|
371
388
|
|
|
372
389
|
if (res.headersSent) {
|
|
@@ -381,11 +398,7 @@ class ModernServer {
|
|
|
381
398
|
context.setParams(params); // route is api service
|
|
382
399
|
|
|
383
400
|
if (route.isApi) {
|
|
384
|
-
|
|
385
|
-
throw new Error('can not found api hanlder');
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
await this.frameAPIHandler(req, res);
|
|
401
|
+
this.handleAPI(context);
|
|
389
402
|
return;
|
|
390
403
|
}
|
|
391
404
|
|
|
@@ -398,12 +411,13 @@ class ModernServer {
|
|
|
398
411
|
return;
|
|
399
412
|
}
|
|
400
413
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
414
|
+
if (route.entryName) {
|
|
415
|
+
await this.emitRouteHook('beforeRender', {
|
|
416
|
+
context
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const file = await this.handleWeb(context, route);
|
|
407
421
|
|
|
408
422
|
if (!file) {
|
|
409
423
|
this.render404(context);
|
|
@@ -421,11 +435,9 @@ class ModernServer {
|
|
|
421
435
|
|
|
422
436
|
if (route.entryName) {
|
|
423
437
|
const templateAPI = (0, _template.createTemplateAPI)(file.content.toString());
|
|
424
|
-
await this.
|
|
438
|
+
await this.emitRouteHook('afterRender', {
|
|
425
439
|
context,
|
|
426
440
|
templateAPI
|
|
427
|
-
}, {
|
|
428
|
-
onLast: _utils2.noop
|
|
429
441
|
});
|
|
430
442
|
await this.injectMicroFE(context, templateAPI);
|
|
431
443
|
response = templateAPI.get();
|
|
@@ -593,6 +605,26 @@ class ModernServer {
|
|
|
593
605
|
res.end((0, _utils2.createErrorDocument)(status, text));
|
|
594
606
|
}
|
|
595
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
|
+
|
|
596
628
|
}
|
|
597
629
|
/* eslint-enable max-lines */
|
|
598
630
|
|
package/dist/js/node/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
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
9
|
const mergeExtension = users => {
|
|
@@ -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
|
+
}
|
|
@@ -3,14 +3,13 @@ import { ModernDevServer } from './dev-server';
|
|
|
3
3
|
import { mergeExtension } from "../../utils.d";
|
|
4
4
|
import { ModernRouteInterface } from "../../libs/route";
|
|
5
5
|
import { ApiServerMode } from "../../constants.d";
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class ModernSSRDevServer extends ModernDevServer {
|
|
7
7
|
protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
|
|
8
8
|
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
9
9
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
10
10
|
}
|
|
11
|
-
export declare class
|
|
12
|
-
protected
|
|
13
|
-
protected prepareAPIHandler(mode: ApiServerMode, extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
11
|
+
export declare class ModernAPIDevServer extends ModernDevServer {
|
|
12
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
14
13
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
15
14
|
protected preServerInit(): Promise<void>;
|
|
16
15
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ModernAPIDevServer, ModernSSRDevServer } from './dev-server-split';
|
|
2
2
|
export { ModernDevServer } from './dev-server';
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { APIServerStartInput } from '@modern-js/server-plugin';
|
|
2
2
|
import { ModernServer } from './modern-server';
|
|
3
3
|
import { mergeExtension } from "../utils.d";
|
|
4
|
-
import { ModernRouteInterface } from "../libs/route";
|
|
4
|
+
import { ModernRoute, ModernRouteInterface, RouteMatcher } from "../libs/route";
|
|
5
5
|
import { ApiServerMode } from "../constants.d";
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
8
11
|
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
9
|
-
protected
|
|
12
|
+
protected preServerInit(): Promise<void>;
|
|
10
13
|
}
|
|
11
|
-
export declare class
|
|
14
|
+
export declare class ModernAPIServer extends ModernServer {
|
|
15
|
+
protected emitRouteHook(_: string, _input: any): Promise<void>;
|
|
16
|
+
protected warmupSSRBundle(): Promise<void>;
|
|
12
17
|
protected prepareWebHandler(_: ReturnType<typeof mergeExtension>): any;
|
|
13
18
|
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
|
|
14
19
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
15
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>;
|
|
16
26
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
3
3
|
import { Adapter, APIServerStartInput } from '@modern-js/server-plugin';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
|
-
import { ModernServerOptions, NextFunction, ServerHookRunner, Measure, Logger, ReadyOptions } from
|
|
6
|
-
import { RouteMatchManager, ModernRouteInterface } from
|
|
7
|
-
import { mergeExtension } from
|
|
5
|
+
import { ModernServerOptions, NextFunction, ServerHookRunner, Measure, 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;
|
|
@@ -20,6 +20,7 @@ export declare class ModernServer {
|
|
|
20
20
|
protected runner: ServerHookRunner;
|
|
21
21
|
protected readonly logger: Logger;
|
|
22
22
|
protected readonly measure: Measure;
|
|
23
|
+
protected readonly proxyTarget: ModernServerOptions['proxyTarget'];
|
|
23
24
|
private readonly isDev;
|
|
24
25
|
private staticFileHandler;
|
|
25
26
|
private routeRenderHandler;
|
|
@@ -35,7 +36,8 @@ export declare class ModernServer {
|
|
|
35
36
|
routes,
|
|
36
37
|
staticGenerate,
|
|
37
38
|
logger,
|
|
38
|
-
measure
|
|
39
|
+
measure,
|
|
40
|
+
proxyTarget
|
|
39
41
|
}: ModernServerOptions);
|
|
40
42
|
getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
|
|
41
43
|
init(runner: ServerHookRunner): Promise<void>;
|
|
@@ -43,21 +45,26 @@ export declare class ModernServer {
|
|
|
43
45
|
onListening(_: Server): void;
|
|
44
46
|
close(): void;
|
|
45
47
|
createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server>;
|
|
46
|
-
protected warmupSSRBundle(): void;
|
|
47
48
|
protected readRouteSpec(): ModernRouteInterface[];
|
|
48
49
|
protected addHandler(handler: ModernServerHandler): void;
|
|
49
50
|
protected render404(context: ModernServerContext): void;
|
|
50
51
|
protected prepareFrameHandler(): Promise<void>;
|
|
52
|
+
protected proxy(): Promise<any>;
|
|
51
53
|
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<Adapter>;
|
|
52
54
|
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<Adapter>;
|
|
53
55
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
56
|
+
protected emitRouteHook(eventName: 'beforeMatch' | 'afterMatch' | 'beforeRender' | 'afterRender', input: any): Promise<any>;
|
|
57
|
+
protected warmupSSRBundle(): void;
|
|
54
58
|
protected preServerInit(): Promise<void>;
|
|
55
|
-
|
|
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;
|
|
56
62
|
private routeHandler;
|
|
57
63
|
private injectMicroFE;
|
|
58
64
|
private compose;
|
|
59
65
|
private requestHandler;
|
|
60
66
|
private onError;
|
|
61
67
|
private renderErrorPage;
|
|
68
|
+
private prepareFavicons;
|
|
62
69
|
}
|
|
63
70
|
export {};
|
package/dist/types/type.d.ts
CHANGED
|
@@ -45,7 +45,12 @@ export declare type ModernServerOptions = {
|
|
|
45
45
|
logger?: Logger;
|
|
46
46
|
measure?: Measure;
|
|
47
47
|
apiOnly?: boolean;
|
|
48
|
+
ssrOnly?: boolean;
|
|
48
49
|
webOnly?: boolean;
|
|
50
|
+
proxyTarget?: {
|
|
51
|
+
ssr?: string;
|
|
52
|
+
api?: string;
|
|
53
|
+
};
|
|
49
54
|
};
|
|
50
55
|
export declare type RenderResult = {
|
|
51
56
|
content: string | Buffer;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const mergeExtension: (users: any[]) => {
|
|
|
3
3
|
};
|
|
4
4
|
export declare const toMessage: (dig: string, e: Error | string) => string;
|
|
5
5
|
export declare const noop: () => void;
|
|
6
|
-
export declare const createErrorDocument: (status: number, text: string) => string;
|
|
6
|
+
export declare const createErrorDocument: (status: number, text: string) => string;
|
|
7
|
+
export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.4-rc.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@babel/preset-typescript": "^7.15.0",
|
|
34
34
|
"@babel/register": "^7.15.3",
|
|
35
35
|
"@babel/runtime": "^7",
|
|
36
|
-
"@modern-js/core": "^1.1.
|
|
37
|
-
"@modern-js/hmr-client": "^1.1.
|
|
36
|
+
"@modern-js/core": "^1.1.4-rc.0",
|
|
37
|
+
"@modern-js/hmr-client": "^1.1.2-rc.0",
|
|
38
38
|
"@modern-js/server-plugin": "^1.1.2",
|
|
39
|
-
"@modern-js/server-utils": "^1.1.
|
|
40
|
-
"@modern-js/bff-utils": "^1.1.
|
|
41
|
-
"@modern-js/utils": "^1.1.
|
|
39
|
+
"@modern-js/server-utils": "^1.1.3-rc.0",
|
|
40
|
+
"@modern-js/bff-utils": "^1.1.2-rc.0",
|
|
41
|
+
"@modern-js/utils": "^1.1.4-rc.0",
|
|
42
42
|
"axios": "^0.21.4",
|
|
43
43
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
44
44
|
"chokidar": "^3.5.2",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@modern-js/module-tools": "^1.1.1",
|
|
65
65
|
"@modern-js/plugin-testing": "^1.1.1",
|
|
66
|
-
"@modern-js/types": "^1.1.
|
|
66
|
+
"@modern-js/types": "^1.1.3-rc.0",
|
|
67
67
|
"@types/jest": "^26",
|
|
68
68
|
"@types/lru-cache": "^5.1.1",
|
|
69
69
|
"@types/mime-types": "^2.1.0",
|
|
@@ -98,5 +98,6 @@
|
|
|
98
98
|
"build": "modern build",
|
|
99
99
|
"dev": "modern build --watch",
|
|
100
100
|
"test": "modern test --passWithNoTests"
|
|
101
|
-
}
|
|
101
|
+
},
|
|
102
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
102
103
|
}
|