@modern-js/server 1.1.4 → 1.2.1-beta.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 +20 -0
- package/dist/js/modern/index.js +1 -7
- package/dist/js/modern/libs/context/context.js +16 -11
- package/dist/js/modern/libs/context/index.js +1 -7
- package/dist/js/modern/libs/{measure.js → metrics.js} +2 -2
- 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 +3 -2
- package/dist/js/modern/libs/route/index.js +2 -1
- package/dist/js/modern/libs/route/route.js +1 -1
- package/dist/js/modern/server/dev-server/dev-server.js +11 -2
- package/dist/js/modern/server/index.js +5 -3
- package/dist/js/modern/server/modern-server.js +22 -13
- package/dist/js/modern/utils.js +1 -9
- package/dist/js/node/index.js +1 -49
- package/dist/js/node/libs/context/context.js +16 -11
- package/dist/js/node/libs/context/index.js +1 -7
- package/dist/js/node/libs/{measure.js → metrics.js} +3 -3
- 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 +3 -2
- package/dist/js/node/libs/route/index.js +6 -0
- package/dist/js/node/libs/route/route.js +1 -1
- package/dist/js/node/server/dev-server/dev-server.js +11 -2
- package/dist/js/node/server/index.js +5 -3
- package/dist/js/node/server/modern-server.js +22 -13
- package/dist/js/node/utils.js +2 -12
- package/dist/types/index.d.ts +1 -3
- package/dist/types/libs/context/context.d.ts +10 -10
- package/dist/types/libs/context/index.d.ts +1 -8
- package/dist/types/libs/metrics.d.ts +3 -0
- 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/libs/route/route.d.ts +2 -10
- package/dist/types/server/modern-server.d.ts +4 -4
- package/dist/types/type.d.ts +12 -5
- package/dist/types/utils.d.ts +1 -2
- package/package.json +11 -9
- package/src/index.ts +2 -8
- package/src/libs/context/context.ts +18 -13
- package/src/libs/context/index.ts +2 -6
- package/src/libs/{measure.ts → metrics.ts} +3 -3
- 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 +5 -1
- package/src/libs/render/type.ts +2 -17
- package/src/libs/route/index.ts +2 -1
- package/src/libs/route/route.ts +4 -20
- package/src/server/dev-server/dev-server.ts +8 -2
- package/src/server/index.ts +3 -3
- package/src/server/modern-server.ts +22 -15
- package/src/type.ts +14 -5
- 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/dist/types/libs/measure.d.ts +0 -3
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,19 +13,28 @@ export class ModernServerContext {
|
|
|
13
13
|
/**
|
|
14
14
|
* url params
|
|
15
15
|
*/
|
|
16
|
-
constructor(req, res
|
|
17
|
-
logger,
|
|
18
|
-
measure
|
|
19
|
-
}) {
|
|
16
|
+
constructor(req, res) {
|
|
20
17
|
this.req = void 0;
|
|
21
18
|
this.res = void 0;
|
|
22
19
|
this.params = {};
|
|
23
20
|
this.logger = void 0;
|
|
24
|
-
this.
|
|
21
|
+
this.metrics = void 0;
|
|
25
22
|
this.req = req;
|
|
26
23
|
this.res = res;
|
|
27
|
-
this.logger = logger;
|
|
28
|
-
this.
|
|
24
|
+
this.logger = req.logger;
|
|
25
|
+
this.metrics = req.metrics;
|
|
26
|
+
this.bind();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bind() {
|
|
30
|
+
const {
|
|
31
|
+
req,
|
|
32
|
+
res
|
|
33
|
+
} = this;
|
|
34
|
+
|
|
35
|
+
req.get = key => this.getReqHeader(key);
|
|
36
|
+
|
|
37
|
+
res.set = (key, value) => this.res.setHeader(key, value);
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
setParams(params) {
|
|
@@ -54,10 +63,6 @@ export class ModernServerContext {
|
|
|
54
63
|
return this.req.headers;
|
|
55
64
|
}
|
|
56
65
|
|
|
57
|
-
set headers(val) {
|
|
58
|
-
this.req.headers = val;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
66
|
get method() {
|
|
62
67
|
return this.req.method;
|
|
63
68
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import { ModernServerContext } from "./context";
|
|
2
|
-
export const createContext = (req, res,
|
|
3
|
-
logger,
|
|
4
|
-
measure
|
|
5
|
-
}) => new ModernServerContext(req, res, {
|
|
6
|
-
logger,
|
|
7
|
-
measure
|
|
8
|
-
});
|
|
2
|
+
export const createContext = (req, res) => new ModernServerContext(req, res);
|
|
9
3
|
export { ModernServerContext };
|
|
@@ -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,
|
|
@@ -25,8 +25,9 @@ export const render = async (ctx, renderOptions) => {
|
|
|
25
25
|
distDir,
|
|
26
26
|
staticGenerate,
|
|
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
|
|
|
@@ -10,7 +10,7 @@ export class ModernRoute {
|
|
|
10
10
|
this.isSSR = void 0;
|
|
11
11
|
this.isSPA = void 0;
|
|
12
12
|
this.enableModernMode = void 0;
|
|
13
|
-
this.entryName = routeSpec.entryName;
|
|
13
|
+
this.entryName = routeSpec.entryName || '';
|
|
14
14
|
this.urlPath = routeSpec.urlPath;
|
|
15
15
|
this.entryPath = routeSpec.entryPath || '';
|
|
16
16
|
this.isSSR = routeSpec.isSSR || false;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
1
7
|
import { createServer } from 'http';
|
|
2
8
|
import path from 'path';
|
|
3
9
|
import { createServer as createHttpsServer } from 'https';
|
|
@@ -25,6 +31,7 @@ const DEFAULT_DEV_OPTIONS = {
|
|
|
25
31
|
dev: {
|
|
26
32
|
writeToDisk: true
|
|
27
33
|
},
|
|
34
|
+
watch: true,
|
|
28
35
|
hot: true,
|
|
29
36
|
liveReload: true
|
|
30
37
|
};
|
|
@@ -41,7 +48,7 @@ export class ModernDevServer extends ModernServer {
|
|
|
41
48
|
this.devMiddleware = void 0;
|
|
42
49
|
this.compiler = options.compiler; // set dev server options, like webpack-dev-server
|
|
43
50
|
|
|
44
|
-
this.dev = typeof options.dev === 'boolean' ? DEFAULT_DEV_OPTIONS : options.dev;
|
|
51
|
+
this.dev = typeof options.dev === 'boolean' ? DEFAULT_DEV_OPTIONS : _objectSpread(_objectSpread({}, DEFAULT_DEV_OPTIONS), options.dev);
|
|
45
52
|
enableRegister(this.pwd, this.conf);
|
|
46
53
|
} // Complete the preparation of services
|
|
47
54
|
|
|
@@ -90,7 +97,9 @@ export class ModernDevServer extends ModernServer {
|
|
|
90
97
|
|
|
91
98
|
await super.init(runner); // watch mock/ server/ api/ dir file change
|
|
92
99
|
|
|
93
|
-
this.
|
|
100
|
+
if (this.dev.watch) {
|
|
101
|
+
this.startWatcher();
|
|
102
|
+
}
|
|
94
103
|
}
|
|
95
104
|
|
|
96
105
|
ready(options = {}) {
|
|
@@ -10,7 +10,7 @@ import { logger as defaultLogger } from '@modern-js/utils';
|
|
|
10
10
|
import { AppContext, initAppContext, initAppDir, loadUserConfig, ConfigContext } from '@modern-js/core';
|
|
11
11
|
import { ModernServer } from "./modern-server";
|
|
12
12
|
import { ModernAPIServer, ModernSSRServer, ModernWebServer } from "./modern-server-split";
|
|
13
|
-
import {
|
|
13
|
+
import { metrics as defaultMetrics } from "../libs/metrics";
|
|
14
14
|
export class Server {
|
|
15
15
|
constructor(options) {
|
|
16
16
|
this.options = void 0;
|
|
@@ -36,7 +36,7 @@ export class Server {
|
|
|
36
36
|
options
|
|
37
37
|
} = this;
|
|
38
38
|
options.logger = options.logger || defaultLogger;
|
|
39
|
-
options.
|
|
39
|
+
options.metrics = options.metrics || defaultMetrics; // initialize server
|
|
40
40
|
|
|
41
41
|
if (options.dev) {
|
|
42
42
|
this.server = this.createDevServer();
|
|
@@ -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({});
|
|
@@ -41,9 +41,11 @@ export class ModernServer {
|
|
|
41
41
|
routes,
|
|
42
42
|
staticGenerate,
|
|
43
43
|
logger,
|
|
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;
|
|
@@ -53,26 +55,26 @@ export class ModernServer {
|
|
|
53
55
|
this.presetRoutes = void 0;
|
|
54
56
|
this.runner = void 0;
|
|
55
57
|
this.logger = void 0;
|
|
56
|
-
this.
|
|
58
|
+
this.metrics = void 0;
|
|
57
59
|
this.proxyTarget = void 0;
|
|
58
60
|
this.isDev = false;
|
|
59
61
|
this.staticFileHandler = void 0;
|
|
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;
|
|
75
|
-
this.
|
|
77
|
+
this.metrics = metrics;
|
|
76
78
|
this.router = new RouteMatchManager();
|
|
77
79
|
this.presetRoutes = routes;
|
|
78
80
|
this.proxyTarget = proxyTarget;
|
|
@@ -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
|
|
|
@@ -313,7 +315,11 @@ export class ModernServer {
|
|
|
313
315
|
}
|
|
314
316
|
|
|
315
317
|
async handleWeb(context, route) {
|
|
316
|
-
return this.routeRenderHandler(
|
|
318
|
+
return this.routeRenderHandler({
|
|
319
|
+
ctx: context,
|
|
320
|
+
route,
|
|
321
|
+
runner: this.runner
|
|
322
|
+
});
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
verifyMatch(_c, _m) {// empty
|
|
@@ -332,7 +338,7 @@ export class ModernServer {
|
|
|
332
338
|
context
|
|
333
339
|
}); // match routes in the route spec
|
|
334
340
|
|
|
335
|
-
const matched = this.router.match(context.
|
|
341
|
+
const matched = this.router.match(context.path);
|
|
336
342
|
|
|
337
343
|
if (!matched) {
|
|
338
344
|
this.render404(context);
|
|
@@ -520,10 +526,9 @@ export class ModernServer {
|
|
|
520
526
|
requestHandler(req, res, next = () => {// empty
|
|
521
527
|
}) {
|
|
522
528
|
res.statusCode = 200;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
});
|
|
529
|
+
req.logger = req.logger || this.logger;
|
|
530
|
+
req.metrics = req.metrics || this.metrics;
|
|
531
|
+
const context = createContext(req, res);
|
|
527
532
|
|
|
528
533
|
try {
|
|
529
534
|
this._handler(context, next);
|
|
@@ -555,7 +560,11 @@ export class ModernServer {
|
|
|
555
560
|
|
|
556
561
|
if (entryName === status.toString() || entryName === '_error') {
|
|
557
562
|
try {
|
|
558
|
-
const file = await this.routeRenderHandler(
|
|
563
|
+
const file = await this.routeRenderHandler({
|
|
564
|
+
route,
|
|
565
|
+
ctx: context,
|
|
566
|
+
runner: this.runner
|
|
567
|
+
});
|
|
559
568
|
|
|
560
569
|
if (file) {
|
|
561
570
|
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,19 +25,28 @@ class ModernServerContext {
|
|
|
25
25
|
/**
|
|
26
26
|
* url params
|
|
27
27
|
*/
|
|
28
|
-
constructor(req, res
|
|
29
|
-
logger,
|
|
30
|
-
measure
|
|
31
|
-
}) {
|
|
28
|
+
constructor(req, res) {
|
|
32
29
|
this.req = void 0;
|
|
33
30
|
this.res = void 0;
|
|
34
31
|
this.params = {};
|
|
35
32
|
this.logger = void 0;
|
|
36
|
-
this.
|
|
33
|
+
this.metrics = void 0;
|
|
37
34
|
this.req = req;
|
|
38
35
|
this.res = res;
|
|
39
|
-
this.logger = logger;
|
|
40
|
-
this.
|
|
36
|
+
this.logger = req.logger;
|
|
37
|
+
this.metrics = req.metrics;
|
|
38
|
+
this.bind();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
bind() {
|
|
42
|
+
const {
|
|
43
|
+
req,
|
|
44
|
+
res
|
|
45
|
+
} = this;
|
|
46
|
+
|
|
47
|
+
req.get = key => this.getReqHeader(key);
|
|
48
|
+
|
|
49
|
+
res.set = (key, value) => this.res.setHeader(key, value);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
setParams(params) {
|
|
@@ -66,10 +75,6 @@ class ModernServerContext {
|
|
|
66
75
|
return this.req.headers;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
set headers(val) {
|
|
70
|
-
this.req.headers = val;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
78
|
get method() {
|
|
74
79
|
return this.req.method;
|
|
75
80
|
}
|
|
@@ -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
|
-
measure
|
|
19
|
-
}) => new _context.ModernServerContext(req, res, {
|
|
20
|
-
logger,
|
|
21
|
-
measure
|
|
22
|
-
});
|
|
16
|
+
const createContext = (req, res) => new _context.ModernServerContext(req, res);
|
|
23
17
|
|
|
24
18
|
exports.createContext = createContext;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.metrics = void 0;
|
|
7
|
+
const metrics = {
|
|
8
8
|
gauges() {// no impl
|
|
9
9
|
},
|
|
10
10
|
|
|
@@ -15,4 +15,4 @@ const measure = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
};
|
|
18
|
-
exports.
|
|
18
|
+
exports.metrics = metrics;
|
|
@@ -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);
|