@modern-js/server 1.1.5-beta.1 → 1.2.1-beta.2
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 +20 -0
- package/dist/js/modern/index.js +1 -7
- package/dist/js/modern/libs/context/context.js +3 -6
- package/dist/js/modern/libs/context/index.js +1 -7
- package/dist/js/modern/libs/hook-api/template.js +4 -4
- package/dist/js/modern/libs/proxy.js +1 -1
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +1 -2
- package/dist/js/modern/libs/render/reader.js +8 -11
- package/dist/js/modern/libs/route/index.js +2 -1
- package/dist/js/modern/server/index.js +4 -2
- package/dist/js/modern/server/modern-server.js +11 -9
- package/dist/js/modern/utils.js +1 -9
- package/dist/js/node/index.js +1 -49
- package/dist/js/node/libs/context/context.js +3 -6
- package/dist/js/node/libs/context/index.js +1 -7
- package/dist/js/node/libs/hook-api/template.js +4 -4
- package/dist/js/node/libs/proxy.js +1 -1
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +1 -2
- package/dist/js/node/libs/render/reader.js +8 -11
- package/dist/js/node/libs/route/index.js +6 -0
- package/dist/js/node/server/index.js +4 -2
- package/dist/js/node/server/modern-server.js +11 -9
- package/dist/js/node/utils.js +2 -12
- package/dist/types/index.d.ts +1 -3
- package/dist/types/libs/context/context.d.ts +7 -7
- package/dist/types/libs/context/index.d.ts +1 -8
- package/dist/types/libs/hook-api/template.d.ts +4 -4
- package/dist/types/libs/route/index.d.ts +2 -1
- package/dist/types/server/modern-server.d.ts +1 -1
- package/dist/types/type.d.ts +6 -0
- package/dist/types/utils.d.ts +1 -2
- package/package.json +13 -10
- package/src/index.ts +2 -8
- package/src/libs/context/context.ts +8 -7
- package/src/libs/context/index.ts +2 -6
- package/src/libs/hook-api/template.ts +4 -4
- package/src/libs/proxy.ts +1 -1
- package/src/libs/render/cache/__tests__/cache.test.ts +2 -2
- package/src/libs/render/reader.ts +8 -8
- package/src/libs/render/type.ts +0 -2
- package/src/libs/route/index.ts +2 -1
- package/src/server/index.ts +2 -2
- package/src/server/modern-server.ts +10 -10
- package/src/type.ts +7 -0
- package/src/utils.ts +0 -14
- package/tests/.eslintrc.js +6 -0
- package/tests/context.test.ts +41 -0
- package/tests/fixtures/hosting-files/static/index.js +1 -0
- package/tests/fixtures/pure/modern.config.js +5 -0
- package/tests/fixtures/pure/package.json +21 -0
- package/tests/fixtures/pure/src/App.css +119 -0
- package/tests/fixtures/pure/src/App.tsx +43 -0
- package/tests/fixtures/pure/tsconfig.json +13 -0
- package/tests/fixtures/route-spec/index.json +29 -0
- package/tests/helper.ts +8 -0
- package/tests/hook.test.ts +44 -0
- package/tests/middleware.test.ts +178 -0
- package/tests/route.test.ts +54 -0
- package/tests/server.test.ts +89 -0
- package/tests/tsconfig.json +14 -0
- package/tests/utils.test.ts +40 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5a4c557e: feat: support bff test
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- e04914ce: add route types, fix metrics types
|
|
12
|
+
- e04914ce: add route types, fix metrics types
|
|
13
|
+
- Updated dependencies [90eeb72c]
|
|
14
|
+
- Updated dependencies [e04914ce]
|
|
15
|
+
- Updated dependencies [5a4c557e]
|
|
16
|
+
- Updated dependencies [e04914ce]
|
|
17
|
+
- Updated dependencies [ca7dcb32]
|
|
18
|
+
- Updated dependencies [ecb344dc]
|
|
19
|
+
- @modern-js/core@1.2.0
|
|
20
|
+
- @modern-js/server-plugin@1.1.3
|
|
21
|
+
- @modern-js/utils@1.1.5
|
|
22
|
+
|
|
3
23
|
## 1.1.4
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { Server } from "./server";
|
|
2
|
-
export * from "./type";
|
|
3
|
-
export * from "./libs/context";
|
|
4
|
-
export * from "./libs/route";
|
|
5
2
|
export { Server };
|
|
6
3
|
export default (options => {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
-
const allowEnvs = ['production', 'development', 'test'];
|
|
9
|
-
|
|
10
4
|
if (options == null) {
|
|
11
|
-
throw new Error();
|
|
5
|
+
throw new Error('can not start mserver without options');
|
|
12
6
|
}
|
|
13
7
|
|
|
14
8
|
const server = new Server(options);
|
|
@@ -13,10 +13,7 @@ export class ModernServerContext {
|
|
|
13
13
|
/**
|
|
14
14
|
* url params
|
|
15
15
|
*/
|
|
16
|
-
constructor(req, res
|
|
17
|
-
logger,
|
|
18
|
-
metrics
|
|
19
|
-
}) {
|
|
16
|
+
constructor(req, res) {
|
|
20
17
|
this.req = void 0;
|
|
21
18
|
this.res = void 0;
|
|
22
19
|
this.params = {};
|
|
@@ -24,8 +21,8 @@ export class ModernServerContext {
|
|
|
24
21
|
this.metrics = void 0;
|
|
25
22
|
this.req = req;
|
|
26
23
|
this.res = res;
|
|
27
|
-
this.logger = logger;
|
|
28
|
-
this.metrics = metrics;
|
|
24
|
+
this.logger = req.logger;
|
|
25
|
+
this.metrics = req.metrics;
|
|
29
26
|
this.bind();
|
|
30
27
|
}
|
|
31
28
|
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import { ModernServerContext } from "./context";
|
|
2
|
-
export const createContext = (req, res,
|
|
3
|
-
logger,
|
|
4
|
-
metrics
|
|
5
|
-
}) => new ModernServerContext(req, res, {
|
|
6
|
-
logger,
|
|
7
|
-
metrics
|
|
8
|
-
});
|
|
2
|
+
export const createContext = (req, res) => new ModernServerContext(req, res);
|
|
9
3
|
export { ModernServerContext };
|
|
@@ -23,28 +23,28 @@ class TemplateAPI {
|
|
|
23
23
|
this.content = content;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
prependHead(fragment) {
|
|
27
27
|
const {
|
|
28
28
|
head
|
|
29
29
|
} = RegList.before;
|
|
30
30
|
return this.replace(head, `${head}${fragment}`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
appendHead(fragment) {
|
|
34
34
|
const {
|
|
35
35
|
head
|
|
36
36
|
} = RegList.after;
|
|
37
37
|
return this.replace(head, `${fragment}${head}`);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
prependBody(fragment) {
|
|
41
41
|
const {
|
|
42
42
|
body
|
|
43
43
|
} = RegList.before;
|
|
44
44
|
return this.replace(body, `${body}${fragment}`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
appendBody(fragment) {
|
|
48
48
|
const {
|
|
49
49
|
body
|
|
50
50
|
} = RegList.after;
|
|
@@ -19,6 +19,7 @@ const createCacheConfig = (config = {}) => _objectSpread({
|
|
|
19
19
|
matches: null
|
|
20
20
|
}, config);
|
|
21
21
|
|
|
22
|
+
jest.setTimeout(60000);
|
|
22
23
|
describe('cache', () => {
|
|
23
24
|
it('should cache correctly', async () => {
|
|
24
25
|
destroyCache();
|
|
@@ -178,7 +179,6 @@ describe('cache', () => {
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
});
|
|
181
|
-
jest.setTimeout(1000 * 10);
|
|
182
182
|
it('should stale cache correctly', async () => {
|
|
183
183
|
destroyCache();
|
|
184
184
|
const cache = createCache();
|
|
@@ -204,7 +204,6 @@ describe('cache', () => {
|
|
|
204
204
|
const staleResult = await cache.get(context);
|
|
205
205
|
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
206
206
|
});
|
|
207
|
-
jest.setTimeout(1000 * 15);
|
|
208
207
|
it('should garbage cache correctly', async () => {
|
|
209
208
|
destroyCache();
|
|
210
209
|
const cache = createCache();
|
|
@@ -15,9 +15,9 @@ const createCacheItem = async (filepath, mtime) => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
class LruReader {
|
|
18
|
+
// private timer?: NodeJS.Timeout;
|
|
18
19
|
constructor() {
|
|
19
20
|
this.cache = void 0;
|
|
20
|
-
this.timer = void 0;
|
|
21
21
|
this.cache = new LRU({
|
|
22
22
|
max: 256 * MB,
|
|
23
23
|
length: getContentLength,
|
|
@@ -26,14 +26,12 @@ class LruReader {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
init() {
|
|
30
|
-
this.timeTask();
|
|
29
|
+
init() {// this.timeTask();
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
close() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
32
|
+
close() {// if (this.timer) {
|
|
33
|
+
// clearInterval(this.timer);
|
|
34
|
+
// }
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
async read(filepath) {
|
|
@@ -92,11 +90,10 @@ class LruReader {
|
|
|
92
90
|
cache.del(filepath);
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
}
|
|
93
|
+
} // private timeTask() {
|
|
94
|
+
// this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
95
|
+
// }
|
|
96
96
|
|
|
97
|
-
timeTask() {
|
|
98
|
-
this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
99
|
-
}
|
|
100
97
|
|
|
101
98
|
}
|
|
102
99
|
|
|
@@ -53,7 +53,7 @@ export class Server {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
listen(port = 8080, listener) {
|
|
56
|
-
this.app.listen(port, () => {
|
|
56
|
+
this.app.listen(process.env.PORT || port, () => {
|
|
57
57
|
if (listener) {
|
|
58
58
|
listener();
|
|
59
59
|
}
|
|
@@ -120,9 +120,11 @@ export class Server {
|
|
|
120
120
|
});
|
|
121
121
|
const appContext = await this.initAppContext();
|
|
122
122
|
serverManager.run(() => {
|
|
123
|
+
var _options$config$outpu;
|
|
124
|
+
|
|
123
125
|
ConfigContext.set(this.options.config);
|
|
124
126
|
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
125
|
-
distDirectory: path.join(options.pwd, options.config.output.path || 'dist')
|
|
127
|
+
distDirectory: path.join(options.pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist')
|
|
126
128
|
}));
|
|
127
129
|
});
|
|
128
130
|
return serverManager.init({});
|
|
@@ -44,6 +44,8 @@ export class ModernServer {
|
|
|
44
44
|
metrics,
|
|
45
45
|
proxyTarget
|
|
46
46
|
}) {
|
|
47
|
+
var _config$output;
|
|
48
|
+
|
|
47
49
|
this.pwd = void 0;
|
|
48
50
|
this.distDir = void 0;
|
|
49
51
|
this.workDir = void 0;
|
|
@@ -60,15 +62,15 @@ export class ModernServer {
|
|
|
60
62
|
this.routeRenderHandler = void 0;
|
|
61
63
|
this.frameWebHandler = null;
|
|
62
64
|
this.frameAPIHandler = null;
|
|
65
|
+
this.proxyHandler = null;
|
|
63
66
|
this._handler = void 0;
|
|
64
67
|
this.staticGenerate = false;
|
|
65
|
-
this.proxyHandler = null;
|
|
66
68
|
|
|
67
69
|
require('ignore-styles');
|
|
68
70
|
|
|
69
71
|
this.isDev = Boolean(dev);
|
|
70
72
|
this.pwd = pwd;
|
|
71
|
-
this.distDir = path.join(pwd, config.output.path || 'dist');
|
|
73
|
+
this.distDir = path.join(pwd, ((_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist');
|
|
72
74
|
this.workDir = this.isDev ? pwd : this.distDir;
|
|
73
75
|
this.conf = config;
|
|
74
76
|
this.logger = logger;
|
|
@@ -128,7 +130,7 @@ export class ModernServer {
|
|
|
128
130
|
const {
|
|
129
131
|
favicon,
|
|
130
132
|
faviconByEntries
|
|
131
|
-
} = this.conf.output;
|
|
133
|
+
} = this.conf.output || {};
|
|
132
134
|
const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
|
|
133
135
|
// Setting `assetPrefix` means these resources should be uploaded to CDN.
|
|
134
136
|
|
|
@@ -175,6 +177,7 @@ export class ModernServer {
|
|
|
175
177
|
|
|
176
178
|
return [];
|
|
177
179
|
} // add promisify request handler to server
|
|
180
|
+
// handler should do not do more things after invoke next
|
|
178
181
|
|
|
179
182
|
|
|
180
183
|
addHandler(handler) {
|
|
@@ -336,7 +339,7 @@ export class ModernServer {
|
|
|
336
339
|
context
|
|
337
340
|
}); // match routes in the route spec
|
|
338
341
|
|
|
339
|
-
const matched = this.router.match(context.
|
|
342
|
+
const matched = this.router.match(context.path);
|
|
340
343
|
|
|
341
344
|
if (!matched) {
|
|
342
345
|
this.render404(context);
|
|
@@ -477,7 +480,7 @@ export class ModernServer {
|
|
|
477
480
|
const injection = JSON.stringify(_objectSpread(_objectSpread({}, manifest), {}, {
|
|
478
481
|
modules
|
|
479
482
|
}));
|
|
480
|
-
templateAPI.
|
|
483
|
+
templateAPI.appendHead(`<script>window.modern_manifest=${injection}</script>`);
|
|
481
484
|
} catch (e) {
|
|
482
485
|
context.error(ERROR_DIGEST.EMICROINJ, e);
|
|
483
486
|
}
|
|
@@ -524,10 +527,9 @@ export class ModernServer {
|
|
|
524
527
|
requestHandler(req, res, next = () => {// empty
|
|
525
528
|
}) {
|
|
526
529
|
res.statusCode = 200;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
});
|
|
530
|
+
req.logger = req.logger || this.logger;
|
|
531
|
+
req.metrics = req.metrics || this.metrics;
|
|
532
|
+
const context = createContext(req, res);
|
|
531
533
|
|
|
532
534
|
try {
|
|
533
535
|
this._handler(context, next);
|
package/dist/js/modern/utils.js
CHANGED
|
@@ -47,12 +47,4 @@ export const createErrorDocument = (status, text) => {
|
|
|
47
47
|
</body>
|
|
48
48
|
</html>
|
|
49
49
|
`;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export function applyMixins(derivedCtor, constructors) {
|
|
53
|
-
constructors.forEach(baseCtor => {
|
|
54
|
-
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
|
55
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
50
|
+
};
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
Server: true
|
|
8
|
-
};
|
|
9
6
|
Object.defineProperty(exports, "Server", {
|
|
10
7
|
enumerable: true,
|
|
11
8
|
get: function () {
|
|
@@ -16,54 +13,9 @@ exports.default = void 0;
|
|
|
16
13
|
|
|
17
14
|
var _server = require("./server");
|
|
18
15
|
|
|
19
|
-
var _type = require("./type");
|
|
20
|
-
|
|
21
|
-
Object.keys(_type).forEach(function (key) {
|
|
22
|
-
if (key === "default" || key === "__esModule") return;
|
|
23
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
24
|
-
if (key in exports && exports[key] === _type[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _type[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
var _context = require("./libs/context");
|
|
34
|
-
|
|
35
|
-
Object.keys(_context).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
38
|
-
if (key in exports && exports[key] === _context[key]) return;
|
|
39
|
-
Object.defineProperty(exports, key, {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () {
|
|
42
|
-
return _context[key];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
var _route = require("./libs/route");
|
|
48
|
-
|
|
49
|
-
Object.keys(_route).forEach(function (key) {
|
|
50
|
-
if (key === "default" || key === "__esModule") return;
|
|
51
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
52
|
-
if (key in exports && exports[key] === _route[key]) return;
|
|
53
|
-
Object.defineProperty(exports, key, {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function () {
|
|
56
|
-
return _route[key];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
16
|
var _default = options => {
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
|
-
const allowEnvs = ['production', 'development', 'test'];
|
|
64
|
-
|
|
65
17
|
if (options == null) {
|
|
66
|
-
throw new Error();
|
|
18
|
+
throw new Error('can not start mserver without options');
|
|
67
19
|
}
|
|
68
20
|
|
|
69
21
|
const server = new _server.Server(options);
|
|
@@ -25,10 +25,7 @@ class ModernServerContext {
|
|
|
25
25
|
/**
|
|
26
26
|
* url params
|
|
27
27
|
*/
|
|
28
|
-
constructor(req, res
|
|
29
|
-
logger,
|
|
30
|
-
metrics
|
|
31
|
-
}) {
|
|
28
|
+
constructor(req, res) {
|
|
32
29
|
this.req = void 0;
|
|
33
30
|
this.res = void 0;
|
|
34
31
|
this.params = {};
|
|
@@ -36,8 +33,8 @@ class ModernServerContext {
|
|
|
36
33
|
this.metrics = void 0;
|
|
37
34
|
this.req = req;
|
|
38
35
|
this.res = res;
|
|
39
|
-
this.logger = logger;
|
|
40
|
-
this.metrics = metrics;
|
|
36
|
+
this.logger = req.logger;
|
|
37
|
+
this.metrics = req.metrics;
|
|
41
38
|
this.bind();
|
|
42
39
|
}
|
|
43
40
|
|
|
@@ -13,12 +13,6 @@ exports.createContext = void 0;
|
|
|
13
13
|
|
|
14
14
|
var _context = require("./context");
|
|
15
15
|
|
|
16
|
-
const createContext = (req, res,
|
|
17
|
-
logger,
|
|
18
|
-
metrics
|
|
19
|
-
}) => new _context.ModernServerContext(req, res, {
|
|
20
|
-
logger,
|
|
21
|
-
metrics
|
|
22
|
-
});
|
|
16
|
+
const createContext = (req, res) => new _context.ModernServerContext(req, res);
|
|
23
17
|
|
|
24
18
|
exports.createContext = createContext;
|
|
@@ -29,28 +29,28 @@ class TemplateAPI {
|
|
|
29
29
|
this.content = content;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
prependHead(fragment) {
|
|
33
33
|
const {
|
|
34
34
|
head
|
|
35
35
|
} = RegList.before;
|
|
36
36
|
return this.replace(head, `${head}${fragment}`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
appendHead(fragment) {
|
|
40
40
|
const {
|
|
41
41
|
head
|
|
42
42
|
} = RegList.after;
|
|
43
43
|
return this.replace(head, `${fragment}${head}`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
prependBody(fragment) {
|
|
47
47
|
const {
|
|
48
48
|
body
|
|
49
49
|
} = RegList.before;
|
|
50
50
|
return this.replace(body, `${body}${fragment}`);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
appendBody(fragment) {
|
|
54
54
|
const {
|
|
55
55
|
body
|
|
56
56
|
} = RegList.after;
|
|
@@ -24,6 +24,7 @@ const createCacheConfig = (config = {}) => _objectSpread({
|
|
|
24
24
|
matches: null
|
|
25
25
|
}, config);
|
|
26
26
|
|
|
27
|
+
jest.setTimeout(60000);
|
|
27
28
|
describe('cache', () => {
|
|
28
29
|
it('should cache correctly', async () => {
|
|
29
30
|
(0, _spr.destroyCache)();
|
|
@@ -183,7 +184,6 @@ describe('cache', () => {
|
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
|
-
jest.setTimeout(1000 * 10);
|
|
187
187
|
it('should stale cache correctly', async () => {
|
|
188
188
|
(0, _spr.destroyCache)();
|
|
189
189
|
const cache = (0, _spr.createCache)();
|
|
@@ -209,7 +209,6 @@ describe('cache', () => {
|
|
|
209
209
|
const staleResult = await cache.get(context);
|
|
210
210
|
expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
|
|
211
211
|
});
|
|
212
|
-
jest.setTimeout(1000 * 15);
|
|
213
212
|
it('should garbage cache correctly', async () => {
|
|
214
213
|
(0, _spr.destroyCache)();
|
|
215
214
|
const cache = (0, _spr.createCache)();
|
|
@@ -26,9 +26,9 @@ const createCacheItem = async (filepath, mtime) => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
class LruReader {
|
|
29
|
+
// private timer?: NodeJS.Timeout;
|
|
29
30
|
constructor() {
|
|
30
31
|
this.cache = void 0;
|
|
31
|
-
this.timer = void 0;
|
|
32
32
|
this.cache = new _lruCache.default({
|
|
33
33
|
max: 256 * MB,
|
|
34
34
|
length: getContentLength,
|
|
@@ -37,14 +37,12 @@ class LruReader {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
init() {
|
|
41
|
-
this.timeTask();
|
|
40
|
+
init() {// this.timeTask();
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
close() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
43
|
+
close() {// if (this.timer) {
|
|
44
|
+
// clearInterval(this.timer);
|
|
45
|
+
// }
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
async read(filepath) {
|
|
@@ -105,11 +103,10 @@ class LruReader {
|
|
|
105
103
|
cache.del(filepath);
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
|
-
}
|
|
106
|
+
} // private timeTask() {
|
|
107
|
+
// this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
108
|
+
// }
|
|
109
109
|
|
|
110
|
-
timeTask() {
|
|
111
|
-
this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
112
|
-
}
|
|
113
110
|
|
|
114
111
|
}
|
|
115
112
|
|
|
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.RouteMatchManager = void 0;
|
|
7
|
+
Object.defineProperty(exports, "RouteMatcher", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _matcher.RouteMatcher;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
|
|
8
14
|
var _matcher = require("./matcher");
|
|
9
15
|
|
|
@@ -69,7 +69,7 @@ class Server {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
listen(port = 8080, listener) {
|
|
72
|
-
this.app.listen(port, () => {
|
|
72
|
+
this.app.listen(process.env.PORT || port, () => {
|
|
73
73
|
if (listener) {
|
|
74
74
|
listener();
|
|
75
75
|
}
|
|
@@ -137,10 +137,12 @@ class Server {
|
|
|
137
137
|
const appContext = await this.initAppContext();
|
|
138
138
|
|
|
139
139
|
_serverPlugin.serverManager.run(() => {
|
|
140
|
+
var _options$config$outpu;
|
|
141
|
+
|
|
140
142
|
_core.ConfigContext.set(this.options.config);
|
|
141
143
|
|
|
142
144
|
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
143
|
-
distDirectory: _path.default.join(options.pwd, options.config.output.path || 'dist')
|
|
145
|
+
distDirectory: _path.default.join(options.pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist')
|
|
144
146
|
}));
|
|
145
147
|
});
|
|
146
148
|
|
|
@@ -74,6 +74,8 @@ class ModernServer {
|
|
|
74
74
|
metrics,
|
|
75
75
|
proxyTarget
|
|
76
76
|
}) {
|
|
77
|
+
var _config$output;
|
|
78
|
+
|
|
77
79
|
this.pwd = void 0;
|
|
78
80
|
this.distDir = void 0;
|
|
79
81
|
this.workDir = void 0;
|
|
@@ -90,15 +92,15 @@ class ModernServer {
|
|
|
90
92
|
this.routeRenderHandler = void 0;
|
|
91
93
|
this.frameWebHandler = null;
|
|
92
94
|
this.frameAPIHandler = null;
|
|
95
|
+
this.proxyHandler = null;
|
|
93
96
|
this._handler = void 0;
|
|
94
97
|
this.staticGenerate = false;
|
|
95
|
-
this.proxyHandler = null;
|
|
96
98
|
|
|
97
99
|
require('ignore-styles');
|
|
98
100
|
|
|
99
101
|
this.isDev = Boolean(dev);
|
|
100
102
|
this.pwd = pwd;
|
|
101
|
-
this.distDir = _path.default.join(pwd, config.output.path || 'dist');
|
|
103
|
+
this.distDir = _path.default.join(pwd, ((_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist');
|
|
102
104
|
this.workDir = this.isDev ? pwd : this.distDir;
|
|
103
105
|
this.conf = config;
|
|
104
106
|
this.logger = logger;
|
|
@@ -158,7 +160,7 @@ class ModernServer {
|
|
|
158
160
|
const {
|
|
159
161
|
favicon,
|
|
160
162
|
faviconByEntries
|
|
161
|
-
} = this.conf.output;
|
|
163
|
+
} = this.conf.output || {};
|
|
162
164
|
const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
|
|
163
165
|
// Setting `assetPrefix` means these resources should be uploaded to CDN.
|
|
164
166
|
|
|
@@ -206,6 +208,7 @@ class ModernServer {
|
|
|
206
208
|
|
|
207
209
|
return [];
|
|
208
210
|
} // add promisify request handler to server
|
|
211
|
+
// handler should do not do more things after invoke next
|
|
209
212
|
|
|
210
213
|
|
|
211
214
|
addHandler(handler) {
|
|
@@ -371,7 +374,7 @@ class ModernServer {
|
|
|
371
374
|
context
|
|
372
375
|
}); // match routes in the route spec
|
|
373
376
|
|
|
374
|
-
const matched = this.router.match(context.
|
|
377
|
+
const matched = this.router.match(context.path);
|
|
375
378
|
|
|
376
379
|
if (!matched) {
|
|
377
380
|
this.render404(context);
|
|
@@ -512,7 +515,7 @@ class ModernServer {
|
|
|
512
515
|
const injection = JSON.stringify(_objectSpread(_objectSpread({}, manifest), {}, {
|
|
513
516
|
modules
|
|
514
517
|
}));
|
|
515
|
-
templateAPI.
|
|
518
|
+
templateAPI.appendHead(`<script>window.modern_manifest=${injection}</script>`);
|
|
516
519
|
} catch (e) {
|
|
517
520
|
context.error(_constants.ERROR_DIGEST.EMICROINJ, e);
|
|
518
521
|
}
|
|
@@ -559,10 +562,9 @@ class ModernServer {
|
|
|
559
562
|
requestHandler(req, res, next = () => {// empty
|
|
560
563
|
}) {
|
|
561
564
|
res.statusCode = 200;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
});
|
|
565
|
+
req.logger = req.logger || this.logger;
|
|
566
|
+
req.metrics = req.metrics || this.metrics;
|
|
567
|
+
const context = (0, _context.createContext)(req, res);
|
|
566
568
|
|
|
567
569
|
try {
|
|
568
570
|
this._handler(context, next);
|
package/dist/js/node/utils.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.applyMixins = applyMixins;
|
|
7
6
|
exports.toMessage = exports.noop = exports.mergeExtension = exports.createErrorDocument = void 0;
|
|
8
7
|
|
|
9
8
|
const mergeExtension = users => {
|
|
@@ -64,15 +63,6 @@ const createErrorDocument = (status, text) => {
|
|
|
64
63
|
</body>
|
|
65
64
|
</html>
|
|
66
65
|
`;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
exports.createErrorDocument = createErrorDocument;
|
|
66
|
+
};
|
|
71
67
|
|
|
72
|
-
|
|
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
|
-
}
|
|
68
|
+
exports.createErrorDocument = createErrorDocument;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ModernServerOptions } from './type';
|
|
2
2
|
import { Server } from './server';
|
|
3
|
-
export * from './type';
|
|
4
|
-
export * from './libs/context';
|
|
5
|
-
export * from './libs/route';
|
|
6
3
|
export type { SSRServerContext } from './libs/render/type';
|
|
7
4
|
export { Server };
|
|
5
|
+
export type { ModernServerOptions };
|
|
8
6
|
|
|
9
7
|
declare const _default: (options: ModernServerOptions) => Promise<Server>;
|
|
10
8
|
|