@modern-js/prod-server 2.5.1-alpha.3 → 2.6.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/cjs/libs/context/context.js +13 -0
- package/dist/cjs/libs/hook-api/index.js +4 -0
- package/dist/cjs/libs/loadConfig.js +5 -0
- package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +4 -0
- package/dist/cjs/libs/render/cache/page-caches/lru.js +4 -0
- package/dist/cjs/libs/render/cache/spr.js +5 -0
- package/dist/cjs/libs/render/cache/util.js +4 -0
- package/dist/cjs/libs/render/index.js +4 -0
- package/dist/cjs/libs/render/reader.js +9 -0
- package/dist/cjs/libs/render/ssr.js +16 -4
- package/dist/cjs/libs/render/static.js +4 -0
- package/dist/cjs/libs/route/index.js +4 -0
- package/dist/cjs/libs/route/matcher.js +4 -0
- package/dist/cjs/libs/serve-file.js +26 -19
- package/dist/cjs/server/index.js +32 -4
- package/dist/cjs/server/modern-server.js +19 -3
- package/dist/esm/libs/context/context.js +15 -6
- package/dist/esm/libs/render/cache/spr.js +1 -0
- package/dist/esm/libs/render/ssr.js +5 -5
- package/dist/esm/libs/route/index.js +4 -0
- package/dist/esm/libs/route/matcher.js +4 -0
- package/dist/esm/libs/serve-file.js +2 -1
- package/dist/esm/server/index.js +30 -7
- package/dist/esm/server/modern-server.js +17 -4
- package/dist/esm-node/libs/context/context.js +9 -0
- package/dist/esm-node/libs/loadConfig.js +1 -0
- package/dist/esm-node/libs/render/cache/spr.js +1 -0
- package/dist/esm-node/libs/render/reader.js +5 -0
- package/dist/esm-node/libs/render/ssr.js +12 -4
- package/dist/esm-node/libs/route/index.js +4 -0
- package/dist/esm-node/libs/route/matcher.js +4 -0
- package/dist/esm-node/libs/serve-file.js +22 -19
- package/dist/esm-node/server/index.js +28 -4
- package/dist/esm-node/server/modern-server.js +15 -3
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/ssr.d.ts +1 -0
- package/dist/types/type.d.ts +1 -8
- package/dist/types/utils.d.ts +1 -1
- package/package.json +9 -9
- package/dist/js/modern/constants.js +0 -35
- package/dist/js/modern/index.js +0 -18
- package/dist/js/modern/libs/context/context.js +0 -160
- package/dist/js/modern/libs/context/index.js +0 -6
- package/dist/js/modern/libs/hook-api/index.js +0 -134
- package/dist/js/modern/libs/hook-api/route.js +0 -20
- package/dist/js/modern/libs/hook-api/template.js +0 -73
- package/dist/js/modern/libs/loadConfig.js +0 -62
- package/dist/js/modern/libs/logger.js +0 -111
- package/dist/js/modern/libs/metrics.js +0 -11
- package/dist/js/modern/libs/proxy.js +0 -92
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +0 -114
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +0 -254
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +0 -47
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +0 -37
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +0 -91
- package/dist/js/modern/libs/render/cache/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +0 -29
- package/dist/js/modern/libs/render/cache/spr.js +0 -248
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +0 -102
- package/dist/js/modern/libs/render/index.js +0 -86
- package/dist/js/modern/libs/render/measure.js +0 -68
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/ssr.js +0 -100
- package/dist/js/modern/libs/render/static.js +0 -60
- package/dist/js/modern/libs/render/type.js +0 -9
- package/dist/js/modern/libs/route/index.js +0 -54
- package/dist/js/modern/libs/route/matcher.js +0 -87
- package/dist/js/modern/libs/route/route.js +0 -16
- package/dist/js/modern/libs/serve-file.js +0 -67
- package/dist/js/modern/server/index.js +0 -208
- package/dist/js/modern/server/modern-server-split.js +0 -74
- package/dist/js/modern/server/modern-server.js +0 -554
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +0 -136
- package/dist/js/modern/worker-server.js +0 -89
- package/dist/js/node/constants.js +0 -62
- package/dist/js/node/index.js +0 -44
- package/dist/js/node/libs/context/context.js +0 -189
- package/dist/js/node/libs/context/index.js +0 -30
- package/dist/js/node/libs/hook-api/index.js +0 -164
- package/dist/js/node/libs/hook-api/route.js +0 -43
- package/dist/js/node/libs/hook-api/template.js +0 -97
- package/dist/js/node/libs/loadConfig.js +0 -91
- package/dist/js/node/libs/logger.js +0 -133
- package/dist/js/node/libs/metrics.js +0 -34
- package/dist/js/node/libs/proxy.js +0 -114
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +0 -115
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +0 -245
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +0 -70
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +0 -60
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +0 -114
- package/dist/js/node/libs/render/cache/index.js +0 -134
- package/dist/js/node/libs/render/cache/page-caches/index.js +0 -55
- package/dist/js/node/libs/render/cache/page-caches/lru.js +0 -58
- package/dist/js/node/libs/render/cache/spr.js +0 -270
- package/dist/js/node/libs/render/cache/type.js +0 -15
- package/dist/js/node/libs/render/cache/util.js +0 -138
- package/dist/js/node/libs/render/index.js +0 -115
- package/dist/js/node/libs/render/measure.js +0 -90
- package/dist/js/node/libs/render/reader.js +0 -140
- package/dist/js/node/libs/render/ssr.js +0 -123
- package/dist/js/node/libs/render/static.js +0 -89
- package/dist/js/node/libs/render/type.js +0 -32
- package/dist/js/node/libs/route/index.js +0 -78
- package/dist/js/node/libs/route/matcher.js +0 -106
- package/dist/js/node/libs/route/route.js +0 -39
- package/dist/js/node/libs/serve-file.js +0 -97
- package/dist/js/node/server/index.js +0 -219
- package/dist/js/node/server/modern-server-split.js +0 -97
- package/dist/js/node/server/modern-server.js +0 -559
- package/dist/js/node/type.js +0 -15
- package/dist/js/node/utils.js +0 -166
- package/dist/js/node/worker-server.js +0 -113
- package/dist/js/treeshaking/constants.js +0 -29
- package/dist/js/treeshaking/index.js +0 -13
- package/dist/js/treeshaking/libs/context/context.js +0 -274
- package/dist/js/treeshaking/libs/context/index.js +0 -5
- package/dist/js/treeshaking/libs/hook-api/index.js +0 -281
- package/dist/js/treeshaking/libs/hook-api/route.js +0 -68
- package/dist/js/treeshaking/libs/hook-api/template.js +0 -127
- package/dist/js/treeshaking/libs/loadConfig.js +0 -82
- package/dist/js/treeshaking/libs/logger.js +0 -205
- package/dist/js/treeshaking/libs/metrics.js +0 -6
- package/dist/js/treeshaking/libs/proxy.js +0 -244
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +0 -291
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +0 -781
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +0 -67
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +0 -45
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +0 -147
- package/dist/js/treeshaking/libs/render/cache/index.js +0 -346
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +0 -154
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +0 -84
- package/dist/js/treeshaking/libs/render/cache/spr.js +0 -492
- package/dist/js/treeshaking/libs/render/cache/type.js +0 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +0 -280
- package/dist/js/treeshaking/libs/render/index.js +0 -234
- package/dist/js/treeshaking/libs/render/measure.js +0 -146
- package/dist/js/treeshaking/libs/render/reader.js +0 -339
- package/dist/js/treeshaking/libs/render/ssr.js +0 -223
- package/dist/js/treeshaking/libs/render/static.js +0 -216
- package/dist/js/treeshaking/libs/render/type.js +0 -7
- package/dist/js/treeshaking/libs/route/index.js +0 -130
- package/dist/js/treeshaking/libs/route/matcher.js +0 -143
- package/dist/js/treeshaking/libs/route/route.js +0 -40
- package/dist/js/treeshaking/libs/serve-file.js +0 -184
- package/dist/js/treeshaking/server/index.js +0 -505
- package/dist/js/treeshaking/server/modern-server-split.js +0 -360
- package/dist/js/treeshaking/server/modern-server.js +0 -1089
- package/dist/js/treeshaking/type.js +0 -1
- package/dist/js/treeshaking/utils.js +0 -147
- package/dist/js/treeshaking/worker-server.js +0 -233
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @modern-js/prod-server
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 36164a2: fix: env.PORT should be respected when using listenOptions
|
|
8
|
+
fix: 当使用 listenOptions 时,env.PORT 应该被支持
|
|
9
|
+
- 49fa0b1: fix: remove header info from SSR ctx to avoid security issues, reserved a switch
|
|
10
|
+
fix: 移除 SSR 上下文中的 header 信息,避免造成安全问题,预留一个字段开启
|
|
11
|
+
- Updated dependencies [e1f799e]
|
|
12
|
+
- Updated dependencies [7915ab3]
|
|
13
|
+
- Updated dependencies [0fe658a]
|
|
14
|
+
- @modern-js/utils@2.6.0
|
|
15
|
+
- @modern-js/server-core@2.6.0
|
|
16
|
+
|
|
3
17
|
## 2.5.0
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -34,6 +38,9 @@ var import_fresh = __toESM(require("fresh"));
|
|
|
34
38
|
var import_utils = require("../../utils");
|
|
35
39
|
class ModernServerContext {
|
|
36
40
|
constructor(req, res, options) {
|
|
41
|
+
/**
|
|
42
|
+
* url params
|
|
43
|
+
*/
|
|
37
44
|
this.params = {};
|
|
38
45
|
this.options = {};
|
|
39
46
|
this.req = req;
|
|
@@ -56,6 +63,7 @@ class ModernServerContext {
|
|
|
56
63
|
this.send(body);
|
|
57
64
|
};
|
|
58
65
|
}
|
|
66
|
+
// compat express res.send, only support etag now
|
|
59
67
|
send(body) {
|
|
60
68
|
try {
|
|
61
69
|
const generateETag = !this.res.getHeader("ETag") && this.options.etag;
|
|
@@ -105,6 +113,7 @@ class ModernServerContext {
|
|
|
105
113
|
}
|
|
106
114
|
return false;
|
|
107
115
|
}
|
|
116
|
+
/* request property */
|
|
108
117
|
get headers() {
|
|
109
118
|
return this.req.headers;
|
|
110
119
|
}
|
|
@@ -165,12 +174,16 @@ class ModernServerContext {
|
|
|
165
174
|
const str = this.querystring;
|
|
166
175
|
return import_querystring.default.parse(str);
|
|
167
176
|
}
|
|
177
|
+
/* response property */
|
|
168
178
|
get status() {
|
|
169
179
|
return this.res.statusCode;
|
|
170
180
|
}
|
|
171
181
|
set status(statusCode) {
|
|
172
182
|
this.res.statusCode = statusCode;
|
|
173
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* 判断链接是否已经关闭
|
|
186
|
+
*/
|
|
174
187
|
resHasHandled() {
|
|
175
188
|
return this.res.writableEnded;
|
|
176
189
|
}
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -53,6 +57,7 @@ const loadConfig = ({
|
|
|
53
57
|
{
|
|
54
58
|
...resolvedConfig,
|
|
55
59
|
plugins: []
|
|
60
|
+
// filter cli plugins
|
|
56
61
|
},
|
|
57
62
|
serverConfig,
|
|
58
63
|
cliConfig
|
|
@@ -13,6 +13,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
return to;
|
|
14
14
|
};
|
|
15
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
16
20
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
21
|
mod
|
|
18
22
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -75,6 +79,7 @@ class CacheManager {
|
|
|
75
79
|
this.cacheOptions = cacheOptions;
|
|
76
80
|
this.cache = new import_lru_cache.default({
|
|
77
81
|
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
82
|
+
// 默认存 100M,最大 600M
|
|
78
83
|
length(n) {
|
|
79
84
|
const len = n.caches.keys().reduce((total, cur) => {
|
|
80
85
|
var _a;
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -44,11 +48,13 @@ const createCacheItem = async (filepath, mtime) => {
|
|
|
44
48
|
};
|
|
45
49
|
};
|
|
46
50
|
class LruReader {
|
|
51
|
+
// private timer?: NodeJS.Timeout;
|
|
47
52
|
constructor() {
|
|
48
53
|
this.cache = new import_lru_cache.default({
|
|
49
54
|
max: 256 * MB,
|
|
50
55
|
length: getContentLength,
|
|
51
56
|
maxAge: 5 * 60 * 5e3
|
|
57
|
+
// 60s
|
|
52
58
|
});
|
|
53
59
|
}
|
|
54
60
|
init() {
|
|
@@ -93,6 +99,9 @@ class LruReader {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
}
|
|
102
|
+
// private timeTask() {
|
|
103
|
+
// this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
104
|
+
// }
|
|
96
105
|
}
|
|
97
106
|
const reader = new LruReader();
|
|
98
107
|
const readFile = async (filepath) => {
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -28,12 +32,19 @@ __export(ssr_exports, {
|
|
|
28
32
|
module.exports = __toCommonJS(ssr_exports);
|
|
29
33
|
var import_path = __toESM(require("path"));
|
|
30
34
|
var import_utils = require("@modern-js/utils");
|
|
31
|
-
var import_cookie = __toESM(require("cookie"));
|
|
32
35
|
var import_cache = __toESM(require("./cache"));
|
|
33
36
|
var import_measure = require("./measure");
|
|
34
37
|
const render = async (ctx, renderOptions, runner) => {
|
|
35
38
|
var _a;
|
|
36
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
urlPath,
|
|
41
|
+
bundle,
|
|
42
|
+
distDir,
|
|
43
|
+
template,
|
|
44
|
+
entryName,
|
|
45
|
+
staticGenerate,
|
|
46
|
+
enableUnsafeCtx = false
|
|
47
|
+
} = renderOptions;
|
|
37
48
|
const bundleJS = import_path.default.join(distDir, bundle);
|
|
38
49
|
const loadableUri = import_path.default.join(distDir, import_utils.LOADABLE_STATS_FILE);
|
|
39
50
|
const loadableStats = import_utils.fs.existsSync(loadableUri) ? require(loadableUri) : "";
|
|
@@ -47,7 +58,6 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
47
58
|
host: ctx.host,
|
|
48
59
|
query: ctx.query,
|
|
49
60
|
url: ctx.href,
|
|
50
|
-
cookieMap: import_cookie.default.parse(ctx.headers.cookie || ""),
|
|
51
61
|
headers: ctx.headers
|
|
52
62
|
},
|
|
53
63
|
response: {
|
|
@@ -63,12 +73,14 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
63
73
|
template,
|
|
64
74
|
loadableStats,
|
|
65
75
|
routeManifest,
|
|
76
|
+
// for streaming ssr
|
|
66
77
|
entryName,
|
|
67
78
|
staticGenerate,
|
|
68
79
|
logger: void 0,
|
|
69
80
|
metrics: void 0,
|
|
70
81
|
req: ctx.req,
|
|
71
|
-
res: ctx.res
|
|
82
|
+
res: ctx.res,
|
|
83
|
+
enableUnsafeCtx
|
|
72
84
|
};
|
|
73
85
|
context.logger = (0, import_measure.createLogger)(context, ctx.logger);
|
|
74
86
|
context.metrics = (0, import_measure.createMetrics)(context, ctx.metrics);
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -27,6 +27,7 @@ class RouteMatchManager {
|
|
|
27
27
|
this.specs = [];
|
|
28
28
|
this.matchers = [];
|
|
29
29
|
}
|
|
30
|
+
// get all routes matches pathname
|
|
30
31
|
filter(pathname) {
|
|
31
32
|
return this.matchers.reduce((matches, matcher) => {
|
|
32
33
|
if (matcher.matchUrlPath(pathname)) {
|
|
@@ -35,6 +36,7 @@ class RouteMatchManager {
|
|
|
35
36
|
return matches;
|
|
36
37
|
}, []);
|
|
37
38
|
}
|
|
39
|
+
// get best match from a set of matches
|
|
38
40
|
best(pathname, matches) {
|
|
39
41
|
let best;
|
|
40
42
|
let matchedLen = 0;
|
|
@@ -50,6 +52,7 @@ class RouteMatchManager {
|
|
|
50
52
|
}
|
|
51
53
|
return best;
|
|
52
54
|
}
|
|
55
|
+
// reset routes matcher
|
|
53
56
|
reset(specs) {
|
|
54
57
|
this.specs = specs;
|
|
55
58
|
const matchers = specs.reduce((ms, spec) => {
|
|
@@ -58,6 +61,7 @@ class RouteMatchManager {
|
|
|
58
61
|
}, []);
|
|
59
62
|
this.matchers = matchers;
|
|
60
63
|
}
|
|
64
|
+
// get best match from all matcher in manager
|
|
61
65
|
match(pathname) {
|
|
62
66
|
const matches = this.filter(pathname);
|
|
63
67
|
const best = this.best(pathname, matches);
|
|
@@ -40,6 +40,7 @@ class RouteMatcher {
|
|
|
40
40
|
this.spec = spec;
|
|
41
41
|
this.setupUrlPath();
|
|
42
42
|
}
|
|
43
|
+
// generate modern route object
|
|
43
44
|
generate(url) {
|
|
44
45
|
const route = new import_route.ModernRoute(this.spec);
|
|
45
46
|
if (this.urlPath) {
|
|
@@ -57,6 +58,7 @@ class RouteMatcher {
|
|
|
57
58
|
return matchResult.params;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
// get match url length
|
|
60
62
|
matchLength(pathname) {
|
|
61
63
|
var _a;
|
|
62
64
|
if (!this.urlReg) {
|
|
@@ -66,6 +68,7 @@ class RouteMatcher {
|
|
|
66
68
|
return ((_a = result == null ? void 0 : result[0]) == null ? void 0 : _a.length) || null;
|
|
67
69
|
}
|
|
68
70
|
}
|
|
71
|
+
// if match url path
|
|
69
72
|
matchUrlPath(requestUrl) {
|
|
70
73
|
let urlWithoutSlash = requestUrl.endsWith("/") && requestUrl !== "/" ? requestUrl.slice(0, -1) : requestUrl;
|
|
71
74
|
urlWithoutSlash = removeHtmlSuffix(urlWithoutSlash);
|
|
@@ -85,6 +88,7 @@ class RouteMatcher {
|
|
|
85
88
|
matchEntry(entryName) {
|
|
86
89
|
return this.spec.entryName === entryName;
|
|
87
90
|
}
|
|
91
|
+
// compiler urlPath to regexp if necessary
|
|
88
92
|
setupUrlPath() {
|
|
89
93
|
const { urlPath } = this.spec;
|
|
90
94
|
this.urlPath = urlPath === "/" ? urlPath : removeTailSlash(urlPath);
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -49,27 +53,30 @@ const faviconFallbackHandler = (context, next) => {
|
|
|
49
53
|
next();
|
|
50
54
|
}
|
|
51
55
|
};
|
|
52
|
-
const createStaticFileHandler = (rules, output = {}) =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const resume = removedPrefix(req, assetPrefix);
|
|
65
|
-
(0, import_serve_static.default)(hitRule.target)(req, res, () => {
|
|
66
|
-
resume();
|
|
67
|
-
next();
|
|
56
|
+
const createStaticFileHandler = (rules, output = {}) => (
|
|
57
|
+
// eslint-disable-next-line consistent-return
|
|
58
|
+
async (context, next) => {
|
|
59
|
+
const { url: requestUrl, req, res } = context;
|
|
60
|
+
const { assetPrefix = "/" } = output;
|
|
61
|
+
const hitRule = rules.find((item) => {
|
|
62
|
+
if ((0, import_utils.isString)(item.path) && requestUrl.startsWith(item.path)) {
|
|
63
|
+
return true;
|
|
64
|
+
} else if ((0, import_utils.isRegExp)(item.path) && item.path.test(requestUrl)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (hitRule) {
|
|
70
|
+
const resume = removedPrefix(req, assetPrefix);
|
|
71
|
+
(0, import_serve_static.default)(hitRule.target)(req, res, () => {
|
|
72
|
+
resume();
|
|
73
|
+
next();
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
return next();
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
|
-
|
|
79
|
+
);
|
|
73
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
81
|
0 && (module.exports = {
|
|
75
82
|
createStaticFileHandler,
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -44,6 +48,20 @@ class Server {
|
|
|
44
48
|
this.options = options;
|
|
45
49
|
this.serverConfig = {};
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 初始化顺序
|
|
53
|
+
* - 读取 .env.{process.env.MODERN_ENV} 文件,加载环境变量
|
|
54
|
+
* - 获取 server runtime config
|
|
55
|
+
* - 设置 context
|
|
56
|
+
* - 创建 hooksRunner
|
|
57
|
+
* - 合并插件,内置插件和 serverConfig 中配置的插件
|
|
58
|
+
* - 执行 config hook
|
|
59
|
+
* - 获取最终的配置
|
|
60
|
+
* - 设置配置到 context
|
|
61
|
+
* - 初始化 server
|
|
62
|
+
* - 执行 prepare hook
|
|
63
|
+
* - 执行 server init
|
|
64
|
+
*/
|
|
47
65
|
async init() {
|
|
48
66
|
const { options } = this;
|
|
49
67
|
this.loadServerEnv(options);
|
|
@@ -58,6 +76,11 @@ class Server {
|
|
|
58
76
|
await this.server.onInit(this.runner, this.app);
|
|
59
77
|
return this;
|
|
60
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute config hooks
|
|
81
|
+
* @param runner
|
|
82
|
+
* @param options
|
|
83
|
+
*/
|
|
61
84
|
runConfigHook(runner, serverConfig) {
|
|
62
85
|
const newServerConfig = runner.config(serverConfig || {});
|
|
63
86
|
return newServerConfig;
|
|
@@ -75,6 +98,10 @@ class Server {
|
|
|
75
98
|
const serverConfig = (0, import_loadConfig.requireConfig)(serverConfigPath);
|
|
76
99
|
this.serverConfig = serverConfig;
|
|
77
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* merge cliConfig and serverConfig
|
|
104
|
+
*/
|
|
78
105
|
async initConfig(runner, options) {
|
|
79
106
|
const { pwd, config } = options;
|
|
80
107
|
const { serverConfig } = this;
|
|
@@ -98,6 +125,9 @@ class Server {
|
|
|
98
125
|
listener == null ? void 0 : listener();
|
|
99
126
|
};
|
|
100
127
|
if (typeof options === "object") {
|
|
128
|
+
if (process.env.PORT) {
|
|
129
|
+
Object.assign(options, { port: process.env.PORT });
|
|
130
|
+
}
|
|
101
131
|
this.app.listen(options, callback);
|
|
102
132
|
} else {
|
|
103
133
|
this.app.listen(process.env.PORT || options || 8080, callback);
|
|
@@ -142,16 +172,14 @@ class Server {
|
|
|
142
172
|
}
|
|
143
173
|
initAppContext() {
|
|
144
174
|
const { options } = this;
|
|
145
|
-
const { pwd: appDirectory, plugins = [], config
|
|
175
|
+
const { pwd: appDirectory, plugins = [], config } = options;
|
|
146
176
|
const serverPlugins = plugins.map((p) => ({
|
|
147
177
|
server: p
|
|
148
178
|
}));
|
|
149
179
|
return {
|
|
150
180
|
appDirectory,
|
|
151
|
-
apiDirectory: appContext == null ? void 0 : appContext.apiDirectory,
|
|
152
|
-
lambdaDirectory: appContext == null ? void 0 : appContext.lambdaDirectory,
|
|
153
|
-
sharedDirectory: (appContext == null ? void 0 : appContext.sharedDirectory) || import_path.default.resolve(appDirectory, import_utils.SHARED_DIR),
|
|
154
181
|
distDirectory: import_path.default.join(appDirectory, config.output.path || "dist"),
|
|
182
|
+
sharedDirectory: import_path.default.resolve(appDirectory, import_utils.SHARED_DIR),
|
|
155
183
|
plugins: serverPlugins
|
|
156
184
|
};
|
|
157
185
|
}
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -72,6 +76,7 @@ class ModernServer {
|
|
|
72
76
|
this.staticGenerate = staticGenerate || false;
|
|
73
77
|
this.runMode = runMode || import_constants.RUN_MODE.FULL;
|
|
74
78
|
}
|
|
79
|
+
// server prepare
|
|
75
80
|
async onInit(runner, app) {
|
|
76
81
|
var _a, _b;
|
|
77
82
|
this.runner = runner;
|
|
@@ -119,6 +124,7 @@ class ModernServer {
|
|
|
119
124
|
this.addHandler(this.routeHandler.bind(this));
|
|
120
125
|
this.compose();
|
|
121
126
|
}
|
|
127
|
+
// server ready
|
|
122
128
|
onRepack(_) {
|
|
123
129
|
}
|
|
124
130
|
addBeforeRouteHandler() {
|
|
@@ -141,6 +147,7 @@ class ModernServer {
|
|
|
141
147
|
const onlyWeb = filepath.startsWith(serverPath);
|
|
142
148
|
this.prepareFrameHandler({ onlyWeb, onlyApi });
|
|
143
149
|
}
|
|
150
|
+
// exposed requestHandler
|
|
144
151
|
getRequestHandler() {
|
|
145
152
|
return this.requestHandler.bind(this);
|
|
146
153
|
}
|
|
@@ -162,6 +169,8 @@ class ModernServer {
|
|
|
162
169
|
async createHTTPServer(handler) {
|
|
163
170
|
return (0, import_http.createServer)(handler);
|
|
164
171
|
}
|
|
172
|
+
/* —————————————————————— function will be overwrite —————————————————————— */
|
|
173
|
+
// get routes info
|
|
165
174
|
getRoutes() {
|
|
166
175
|
if (this.presetRoutes) {
|
|
167
176
|
return this.presetRoutes;
|
|
@@ -173,9 +182,12 @@ class ModernServer {
|
|
|
173
182
|
}
|
|
174
183
|
return [];
|
|
175
184
|
}
|
|
185
|
+
// add promisify request handler to server
|
|
186
|
+
// handler should do not do more things after invoke next
|
|
176
187
|
addHandler(handler) {
|
|
177
188
|
this.handlers.push(handler);
|
|
178
189
|
}
|
|
190
|
+
// return 404 page
|
|
179
191
|
render404(context) {
|
|
180
192
|
context.error(import_constants.ERROR_DIGEST.ENOTF, "404 Not Found");
|
|
181
193
|
this.renderErrorPage(context, 404);
|
|
@@ -193,6 +205,7 @@ class ModernServer {
|
|
|
193
205
|
);
|
|
194
206
|
this.beforeRouteHandler = handler;
|
|
195
207
|
}
|
|
208
|
+
// gather frame extension and get framework handler
|
|
196
209
|
async prepareFrameHandler(options) {
|
|
197
210
|
const { workDir, runner } = this;
|
|
198
211
|
const { onlyApi, onlyWeb } = options || {};
|
|
@@ -230,7 +243,6 @@ class ModernServer {
|
|
|
230
243
|
pwd: workDir,
|
|
231
244
|
config: extension,
|
|
232
245
|
prefix: Array.isArray(prefix) ? prefix[0] : prefix,
|
|
233
|
-
httpMethodDecider: bff == null ? void 0 : bff.httpMethodDecider,
|
|
234
246
|
render: this.render.bind(this)
|
|
235
247
|
},
|
|
236
248
|
{ onLast: () => null }
|
|
@@ -263,6 +275,7 @@ class ModernServer {
|
|
|
263
275
|
async proxy() {
|
|
264
276
|
return null;
|
|
265
277
|
}
|
|
278
|
+
// warmup ssr function
|
|
266
279
|
warmupSSRBundle() {
|
|
267
280
|
const { distDir } = this;
|
|
268
281
|
const bundles = this.router.getBundles();
|
|
@@ -276,6 +289,8 @@ class ModernServer {
|
|
|
276
289
|
createContext(req, res, options = {}) {
|
|
277
290
|
return (0, import_context.createContext)(req, res, options);
|
|
278
291
|
}
|
|
292
|
+
/* —————————————————————— private function —————————————————————— */
|
|
293
|
+
// handler route.json, include api / csr / ssr
|
|
279
294
|
async routeHandler(context) {
|
|
280
295
|
const { res } = context;
|
|
281
296
|
const matched = this.router.match(context.path);
|
|
@@ -356,7 +371,7 @@ class ModernServer {
|
|
|
356
371
|
(0, import_template.templateInjectableStream)({
|
|
357
372
|
prependHead: route.entryName ? `<script>window._SERVER_DATA=${JSON.stringify(
|
|
358
373
|
context.serverData
|
|
359
|
-
)}
|
|
374
|
+
)}</script>` : void 0
|
|
360
375
|
})
|
|
361
376
|
).pipe(res);
|
|
362
377
|
return;
|
|
@@ -376,7 +391,7 @@ class ModernServer {
|
|
|
376
391
|
afterRenderContext.template.prependHead(
|
|
377
392
|
`<script>window._SERVER_DATA=${JSON.stringify(
|
|
378
393
|
context.serverData
|
|
379
|
-
)}
|
|
394
|
+
)}</script>`
|
|
380
395
|
);
|
|
381
396
|
response = afterRenderContext.template.get();
|
|
382
397
|
}
|
|
@@ -392,6 +407,7 @@ class ModernServer {
|
|
|
392
407
|
}
|
|
393
408
|
return false;
|
|
394
409
|
}
|
|
410
|
+
// compose handlers and create the final handler
|
|
395
411
|
compose() {
|
|
396
412
|
const { handlers } = this;
|
|
397
413
|
if (!Array.isArray(handlers)) {
|
|
@@ -47,9 +47,15 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
47
47
|
"use strict";
|
|
48
48
|
function ModernServerContext(req, res, options) {
|
|
49
49
|
_classCallCheck(this, ModernServerContext);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
/**
|
|
51
|
+
* http request
|
|
52
|
+
*/ _defineProperty(this, "req", void 0);
|
|
53
|
+
/**
|
|
54
|
+
* http response
|
|
55
|
+
*/ _defineProperty(this, "res", void 0);
|
|
56
|
+
/**
|
|
57
|
+
* url params
|
|
58
|
+
*/ _defineProperty(this, "params", {});
|
|
53
59
|
_defineProperty(this, "serverData", void 0);
|
|
54
60
|
_defineProperty(this, "options", {});
|
|
55
61
|
this.req = req;
|
|
@@ -88,6 +94,7 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
88
94
|
}
|
|
89
95
|
},
|
|
90
96
|
{
|
|
97
|
+
// compat express res.send, only support etag now
|
|
91
98
|
key: "send",
|
|
92
99
|
value: function send(body) {
|
|
93
100
|
try {
|
|
@@ -155,7 +162,7 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
155
162
|
},
|
|
156
163
|
{
|
|
157
164
|
key: "headers",
|
|
158
|
-
get: function get() {
|
|
165
|
+
get: /* request property */ function get() {
|
|
159
166
|
return this.req.headers;
|
|
160
167
|
}
|
|
161
168
|
},
|
|
@@ -248,7 +255,7 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
248
255
|
},
|
|
249
256
|
{
|
|
250
257
|
key: "status",
|
|
251
|
-
get: function get() {
|
|
258
|
+
get: /* response property */ function get() {
|
|
252
259
|
return this.res.statusCode;
|
|
253
260
|
},
|
|
254
261
|
set: function set(statusCode) {
|
|
@@ -256,7 +263,9 @@ var ModernServerContext = /*#__PURE__*/ function() {
|
|
|
256
263
|
}
|
|
257
264
|
},
|
|
258
265
|
{
|
|
259
|
-
|
|
266
|
+
/**
|
|
267
|
+
* 判断链接是否已经关闭
|
|
268
|
+
*/ key: "resHasHandled",
|
|
260
269
|
value: function resHasHandled() {
|
|
261
270
|
return this.res.writableEnded;
|
|
262
271
|
}
|
|
@@ -203,6 +203,7 @@ var CacheManager = /*#__PURE__*/ function() {
|
|
|
203
203
|
this.cacheOptions = cacheOptions;
|
|
204
204
|
this.cache = new LRUCache({
|
|
205
205
|
max: Math.min(MAX_SIZE_EACH_CLUSTER, 600) * 1024 * 1024,
|
|
206
|
+
// 默认存 100M,最大 600M
|
|
206
207
|
length: function length(n) {
|
|
207
208
|
var len = n.caches.keys().reduce(function(total, cur) {
|
|
208
209
|
var _n_caches_peek;
|