@modern-js/server 1.2.0 → 1.2.1-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 +14 -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/index.js +6 -2
- package/dist/js/modern/libs/render/reader.js +8 -11
- package/dist/js/modern/libs/render/ssr.js +2 -1
- package/dist/js/modern/libs/route/index.js +2 -1
- package/dist/js/modern/server/index.js +3 -1
- package/dist/js/modern/server/modern-server.js +21 -11
- 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/index.js +6 -2
- package/dist/js/node/libs/render/reader.js +8 -11
- package/dist/js/node/libs/render/ssr.js +2 -1
- package/dist/js/node/libs/route/index.js +6 -0
- package/dist/js/node/server/index.js +3 -1
- package/dist/js/node/server/modern-server.js +21 -11
- 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/render/index.d.ts +10 -1
- package/dist/types/libs/render/ssr.d.ts +2 -1
- package/dist/types/libs/render/type.d.ts +2 -21
- 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 +14 -12
- 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/index.ts +21 -11
- package/src/libs/render/reader.ts +8 -8
- package/src/libs/render/ssr.ts +4 -0
- package/src/libs/render/type.ts +2 -17
- package/src/libs/route/index.ts +2 -1
- package/src/server/index.ts +1 -1
- package/src/server/modern-server.ts +20 -12
- 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,19 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.2.1-rc.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e51b1db3: feat: support custom sdk, interceptor, headers for bff request
|
|
8
|
+
- Updated dependencies [e51b1db3]
|
|
9
|
+
- Updated dependencies [b7fb82ec]
|
|
10
|
+
- @modern-js/server-plugin@1.1.4-rc.0
|
|
11
|
+
- @modern-js/utils@1.1.6-rc.0
|
|
12
|
+
- @modern-js/core@1.2.1-rc.0
|
|
13
|
+
- @modern-js/bff-utils@1.1.2-rc.0
|
|
14
|
+
- @modern-js/hmr-client@1.1.2-rc.0
|
|
15
|
+
- @modern-js/server-utils@1.1.3-rc.0
|
|
16
|
+
|
|
3
17
|
## 1.2.0
|
|
4
18
|
|
|
5
19
|
### Minor 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();
|
|
@@ -9,7 +9,11 @@ import { ERROR_DIGEST } from "../../constants";
|
|
|
9
9
|
export const createRenderHandler = ({
|
|
10
10
|
distDir,
|
|
11
11
|
staticGenerate
|
|
12
|
-
}) => async function render(
|
|
12
|
+
}) => async function render({
|
|
13
|
+
ctx,
|
|
14
|
+
route,
|
|
15
|
+
runner
|
|
16
|
+
}) {
|
|
13
17
|
if (ctx.resHasHandled()) {
|
|
14
18
|
return null;
|
|
15
19
|
}
|
|
@@ -39,7 +43,7 @@ export const createRenderHandler = ({
|
|
|
39
43
|
bundle: route.bundle,
|
|
40
44
|
template: templateHTML,
|
|
41
45
|
staticGenerate
|
|
42
|
-
});
|
|
46
|
+
}, runner);
|
|
43
47
|
return result;
|
|
44
48
|
} catch (err) {
|
|
45
49
|
ctx.error(ERROR_DIGEST.ERENDER, err.stack);
|
|
@@ -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
|
|
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import { SERVER_RENDER_FUNCTION_NAME } from '@modern-js/utils';
|
|
3
3
|
import mime from 'mime-types';
|
|
4
4
|
import cache from "./cache";
|
|
5
|
-
export const render = async (ctx, renderOptions) => {
|
|
5
|
+
export const render = async (ctx, renderOptions, runner) => {
|
|
6
6
|
const {
|
|
7
7
|
bundle,
|
|
8
8
|
distDir,
|
|
@@ -27,6 +27,7 @@ export const render = async (ctx, renderOptions) => {
|
|
|
27
27
|
logger: ctx.logger,
|
|
28
28
|
metrics: ctx.metrics
|
|
29
29
|
};
|
|
30
|
+
runner.extendSSRContext(context);
|
|
30
31
|
|
|
31
32
|
const serverRender = require(bundleJS)[SERVER_RENDER_FUNCTION_NAME];
|
|
32
33
|
|
|
@@ -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) {
|
|
@@ -313,7 +316,11 @@ export class ModernServer {
|
|
|
313
316
|
}
|
|
314
317
|
|
|
315
318
|
async handleWeb(context, route) {
|
|
316
|
-
return this.routeRenderHandler(
|
|
319
|
+
return this.routeRenderHandler({
|
|
320
|
+
ctx: context,
|
|
321
|
+
route,
|
|
322
|
+
runner: this.runner
|
|
323
|
+
});
|
|
317
324
|
}
|
|
318
325
|
|
|
319
326
|
verifyMatch(_c, _m) {// empty
|
|
@@ -332,7 +339,7 @@ export class ModernServer {
|
|
|
332
339
|
context
|
|
333
340
|
}); // match routes in the route spec
|
|
334
341
|
|
|
335
|
-
const matched = this.router.match(context.
|
|
342
|
+
const matched = this.router.match(context.path);
|
|
336
343
|
|
|
337
344
|
if (!matched) {
|
|
338
345
|
this.render404(context);
|
|
@@ -473,7 +480,7 @@ export class ModernServer {
|
|
|
473
480
|
const injection = JSON.stringify(_objectSpread(_objectSpread({}, manifest), {}, {
|
|
474
481
|
modules
|
|
475
482
|
}));
|
|
476
|
-
templateAPI.
|
|
483
|
+
templateAPI.appendHead(`<script>window.modern_manifest=${injection}</script>`);
|
|
477
484
|
} catch (e) {
|
|
478
485
|
context.error(ERROR_DIGEST.EMICROINJ, e);
|
|
479
486
|
}
|
|
@@ -520,10 +527,9 @@ export class ModernServer {
|
|
|
520
527
|
requestHandler(req, res, next = () => {// empty
|
|
521
528
|
}) {
|
|
522
529
|
res.statusCode = 200;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
});
|
|
530
|
+
req.logger = req.logger || this.logger;
|
|
531
|
+
req.metrics = req.metrics || this.metrics;
|
|
532
|
+
const context = createContext(req, res);
|
|
527
533
|
|
|
528
534
|
try {
|
|
529
535
|
this._handler(context, next);
|
|
@@ -555,7 +561,11 @@ export class ModernServer {
|
|
|
555
561
|
|
|
556
562
|
if (entryName === status.toString() || entryName === '_error') {
|
|
557
563
|
try {
|
|
558
|
-
const file = await this.routeRenderHandler(
|
|
564
|
+
const file = await this.routeRenderHandler({
|
|
565
|
+
route,
|
|
566
|
+
ctx: context,
|
|
567
|
+
runner: this.runner
|
|
568
|
+
});
|
|
559
569
|
|
|
560
570
|
if (file) {
|
|
561
571
|
context.res.end(file.content);
|
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)();
|
|
@@ -30,7 +30,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
30
30
|
const createRenderHandler = ({
|
|
31
31
|
distDir,
|
|
32
32
|
staticGenerate
|
|
33
|
-
}) => async function render(
|
|
33
|
+
}) => async function render({
|
|
34
|
+
ctx,
|
|
35
|
+
route,
|
|
36
|
+
runner
|
|
37
|
+
}) {
|
|
34
38
|
if (ctx.resHasHandled()) {
|
|
35
39
|
return null;
|
|
36
40
|
}
|
|
@@ -63,7 +67,7 @@ const createRenderHandler = ({
|
|
|
63
67
|
bundle: route.bundle,
|
|
64
68
|
template: templateHTML,
|
|
65
69
|
staticGenerate
|
|
66
|
-
});
|
|
70
|
+
}, runner);
|
|
67
71
|
return result;
|
|
68
72
|
} catch (err) {
|
|
69
73
|
ctx.error(_constants.ERROR_DIGEST.ERENDER, err.stack);
|
|
@@ -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
|
|
|
@@ -15,7 +15,7 @@ var _cache = _interopRequireDefault(require("./cache"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
const render = async (ctx, renderOptions) => {
|
|
18
|
+
const render = async (ctx, renderOptions, runner) => {
|
|
19
19
|
const {
|
|
20
20
|
bundle,
|
|
21
21
|
distDir,
|
|
@@ -42,6 +42,7 @@ const render = async (ctx, renderOptions) => {
|
|
|
42
42
|
logger: ctx.logger,
|
|
43
43
|
metrics: ctx.metrics
|
|
44
44
|
};
|
|
45
|
+
runner.extendSSRContext(context);
|
|
45
46
|
|
|
46
47
|
const serverRender = require(bundleJS)[_utils.SERVER_RENDER_FUNCTION_NAME];
|
|
47
48
|
|
|
@@ -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
|
|
|
@@ -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
|
|