@modern-js/prod-server 2.4.1-beta.0 → 2.5.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 +18 -3
- package/dist/{js/node → cjs}/constants.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/libs/context/context.js +0 -0
- package/dist/{js/node → cjs}/libs/context/index.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/index.js +12 -25
- package/dist/{js/node → cjs}/libs/hook-api/route.js +0 -0
- package/dist/{js/node → cjs}/libs/hook-api/template.js +0 -0
- package/dist/{js/node → cjs}/libs/loadConfig.js +6 -21
- package/dist/{js/node → cjs}/libs/logger.js +5 -16
- package/dist/{js/node → cjs}/libs/metrics.js +0 -0
- package/dist/{js/node → cjs}/libs/proxy.js +6 -39
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.fun.test.js +12 -34
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cache.test.js +43 -78
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/cjs/libs/render/cache/index.js +97 -0
- package/dist/cjs/libs/render/cache/page-caches/index.js +33 -0
- package/dist/{js/node → cjs}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/spr.js +69 -97
- package/dist/{js/node → cjs}/libs/render/cache/type.js +0 -0
- package/dist/{js/node → cjs}/libs/render/cache/util.js +19 -41
- package/dist/cjs/libs/render/index.js +93 -0
- package/dist/{js/node → cjs}/libs/render/measure.js +6 -21
- package/dist/{js/node → cjs}/libs/render/reader.js +24 -46
- package/dist/{js/node → cjs}/libs/render/ssr.js +3 -23
- package/dist/{js/node → cjs}/libs/render/static.js +22 -44
- package/dist/{js/node → cjs}/libs/render/type.js +0 -0
- package/dist/{js/node → cjs}/libs/route/index.js +0 -0
- package/dist/{js/node → cjs}/libs/route/matcher.js +0 -0
- package/dist/{js/node → cjs}/libs/route/route.js +0 -0
- package/dist/{js/node → cjs}/libs/serve-file.js +2 -22
- package/dist/{js/node → cjs}/server/index.js +56 -106
- package/dist/{js/node → cjs}/server/modern-server-split.js +9 -40
- package/dist/cjs/server/modern-server.js +490 -0
- package/dist/{js/node → cjs}/type.js +0 -0
- package/dist/{js/node → cjs}/utils.js +1 -15
- package/dist/{js/node → cjs}/worker-server.js +3 -23
- package/dist/{js/treeshaking → esm}/constants.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/context/context.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/context/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/hook-api/template.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/loadConfig.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/logger.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/metrics.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/proxy.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.fun.test.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cache.test.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/spr.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/cache/util.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/index.js +4 -3
- package/dist/{js/treeshaking → esm}/libs/render/measure.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/reader.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/ssr.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/static.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/render/type.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/matcher.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/route/route.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/serve-file.js +0 -0
- package/dist/{js/treeshaking → esm}/server/index.js +0 -0
- package/dist/{js/treeshaking → esm}/server/modern-server-split.js +0 -0
- package/dist/{js/treeshaking → esm}/server/modern-server.js +14 -8
- package/dist/{js/treeshaking → esm}/type.js +0 -0
- package/dist/{js/treeshaking → esm}/utils.js +0 -0
- package/dist/{js/treeshaking → esm}/worker-server.js +0 -0
- package/dist/{js/modern → esm-node}/constants.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/context.js +0 -0
- package/dist/{js/modern → esm-node}/libs/context/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/index.js +12 -27
- package/dist/{js/modern → esm-node}/libs/hook-api/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/hook-api/template.js +0 -0
- package/dist/esm-node/libs/loadConfig.js +45 -0
- package/dist/{js/modern → esm-node}/libs/logger.js +5 -18
- package/dist/{js/modern → esm-node}/libs/metrics.js +0 -0
- package/dist/{js/modern → esm-node}/libs/proxy.js +6 -41
- package/dist/esm-node/libs/render/cache/__tests__/cache.fun.test.js +83 -0
- package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +210 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/cacheable.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/error-configuration.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/__tests__/matched-cache.js +0 -0
- package/dist/esm-node/libs/render/cache/index.js +76 -0
- package/dist/esm-node/libs/render/cache/page-caches/index.js +10 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/page-caches/lru.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/spr.js +69 -97
- package/dist/{js/modern → esm-node}/libs/render/cache/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/render/cache/util.js +19 -41
- package/dist/esm-node/libs/render/index.js +64 -0
- package/dist/{js/modern → esm-node}/libs/render/measure.js +6 -23
- package/dist/esm-node/libs/render/reader.js +85 -0
- package/dist/{js/modern → esm-node}/libs/render/ssr.js +3 -23
- package/dist/esm-node/libs/render/static.js +38 -0
- package/dist/{js/modern → esm-node}/libs/render/type.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/index.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/matcher.js +0 -0
- package/dist/{js/modern → esm-node}/libs/route/route.js +0 -0
- package/dist/{js/modern → esm-node}/libs/serve-file.js +2 -22
- package/dist/esm-node/server/index.js +156 -0
- package/dist/esm-node/server/modern-server-split.js +43 -0
- package/dist/esm-node/server/modern-server.js +483 -0
- package/dist/{js/modern → esm-node}/type.js +0 -0
- package/dist/{js/modern → esm-node}/utils.js +1 -17
- package/dist/{js/modern → esm-node}/worker-server.js +3 -23
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/render/index.d.ts +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +15 -16
- package/dist/js/modern/libs/loadConfig.js +0 -62
- 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/index.js +0 -115
- package/dist/js/modern/libs/render/cache/page-caches/index.js +0 -32
- package/dist/js/modern/libs/render/index.js +0 -84
- package/dist/js/modern/libs/render/reader.js +0 -107
- package/dist/js/modern/libs/render/static.js +0 -60
- 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 -548
- 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/index.js +0 -113
- package/dist/js/node/server/modern-server.js +0 -553
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
# @modern-js/prod-server
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.5.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 89ca6cc: refactor: merge build-config into scripts/build
|
|
8
|
+
|
|
9
|
+
refactor: 把 build-config 合并进 scripts/build
|
|
10
|
+
|
|
11
|
+
- 6fca567: feat: support bff handle complete server, include page render
|
|
12
|
+
feat: 支持 bff 处理整个服务,包括页面渲染
|
|
13
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
|
14
|
+
chore: 更改 package.json entry 字段以及构建配置
|
|
7
15
|
- 11c053b: feat: ssr support deploy worker
|
|
8
16
|
|
|
9
17
|
feat: ssr 支持边缘部署
|
|
10
18
|
|
|
19
|
+
- 169c58b: feat: support force csr config
|
|
20
|
+
feat: 支持强制 CSR 的配置
|
|
21
|
+
- Updated dependencies [89ca6cc]
|
|
22
|
+
- Updated dependencies [6fca567]
|
|
23
|
+
- Updated dependencies [30614fa]
|
|
24
|
+
- Updated dependencies [1b0ce87]
|
|
11
25
|
- Updated dependencies [11c053b]
|
|
12
|
-
|
|
13
|
-
- @modern-js/
|
|
26
|
+
- Updated dependencies [169c58b]
|
|
27
|
+
- @modern-js/server-core@2.5.0
|
|
28
|
+
- @modern-js/utils@2.5.0
|
|
14
29
|
|
|
15
30
|
## 2.4.0
|
|
16
31
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -133,27 +116,31 @@ const base = (context) => {
|
|
|
133
116
|
};
|
|
134
117
|
const createAfterMatchContext = (context, entryName) => {
|
|
135
118
|
const baseContext = base(context);
|
|
136
|
-
return
|
|
119
|
+
return {
|
|
120
|
+
...baseContext,
|
|
137
121
|
router: new import_route.RouteAPI(entryName)
|
|
138
|
-
}
|
|
122
|
+
};
|
|
139
123
|
};
|
|
140
124
|
const createAfterRenderContext = (context, content) => {
|
|
141
125
|
const baseContext = base(context);
|
|
142
|
-
return
|
|
126
|
+
return {
|
|
127
|
+
...baseContext,
|
|
143
128
|
template: new import_template.TemplateAPI(content)
|
|
144
|
-
}
|
|
129
|
+
};
|
|
145
130
|
};
|
|
146
131
|
const createMiddlewareContext = (context) => {
|
|
147
132
|
const baseContext = base(context);
|
|
148
|
-
return
|
|
149
|
-
|
|
133
|
+
return {
|
|
134
|
+
...baseContext,
|
|
135
|
+
response: {
|
|
136
|
+
...baseContext.response,
|
|
150
137
|
locals: context.res.locals || {}
|
|
151
|
-
}
|
|
138
|
+
},
|
|
152
139
|
source: {
|
|
153
140
|
req: context.req,
|
|
154
141
|
res: context.res
|
|
155
142
|
}
|
|
156
|
-
}
|
|
143
|
+
};
|
|
157
144
|
};
|
|
158
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
159
146
|
0 && (module.exports = {
|
|
File without changes
|
|
File without changes
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -67,17 +50,19 @@ const loadConfig = ({
|
|
|
67
50
|
if (process.env.NODE_ENV === "production") {
|
|
68
51
|
const resolvedConfig = requireConfig(resolvedConfigPath);
|
|
69
52
|
config = (0, import_merge_deep.default)(
|
|
70
|
-
|
|
53
|
+
{
|
|
54
|
+
...resolvedConfig,
|
|
71
55
|
plugins: []
|
|
72
|
-
}
|
|
56
|
+
},
|
|
73
57
|
serverConfig,
|
|
74
58
|
cliConfig
|
|
75
59
|
);
|
|
76
60
|
} else {
|
|
77
61
|
config = (0, import_merge_deep.default)(
|
|
78
|
-
|
|
62
|
+
{
|
|
63
|
+
...cliConfig,
|
|
79
64
|
plugins: []
|
|
80
|
-
}
|
|
65
|
+
},
|
|
81
66
|
serverConfig
|
|
82
67
|
);
|
|
83
68
|
}
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
5
|
var __export = (target, all) => {
|
|
20
6
|
for (var name in all)
|
|
21
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -77,8 +63,11 @@ const DEFAULT_CONFIG = {
|
|
|
77
63
|
class Logger {
|
|
78
64
|
constructor(options = {}) {
|
|
79
65
|
this.level = options.level || LOG_TYPES.log.level;
|
|
80
|
-
this.config =
|
|
81
|
-
this.types =
|
|
66
|
+
this.config = { ...DEFAULT_CONFIG, ...options.config || {} };
|
|
67
|
+
this.types = {
|
|
68
|
+
...LOG_TYPES,
|
|
69
|
+
...options.types || {}
|
|
70
|
+
};
|
|
82
71
|
this.longestLabel = this.getLongestLabel();
|
|
83
72
|
Object.keys(this.types).forEach((type) => {
|
|
84
73
|
this[type] = this._log.bind(this, type);
|
|
File without changes
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
5
|
var __export = (target, all) => {
|
|
20
6
|
for (var name in all)
|
|
21
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,26 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
29
15
|
return to;
|
|
30
16
|
};
|
|
31
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
18
|
var proxy_exports = {};
|
|
53
19
|
__export(proxy_exports, {
|
|
54
20
|
createProxyHandler: () => createProxyHandler,
|
|
@@ -68,11 +34,12 @@ function formatProxyOptions(proxyOptions) {
|
|
|
68
34
|
Object.keys(proxyOptions).reduce(
|
|
69
35
|
(total, source) => {
|
|
70
36
|
const option = proxyOptions[source];
|
|
71
|
-
total.push(
|
|
37
|
+
total.push({
|
|
72
38
|
context: source,
|
|
73
39
|
changeOrigin: true,
|
|
74
|
-
logLevel: "warn"
|
|
75
|
-
|
|
40
|
+
logLevel: "warn",
|
|
41
|
+
...typeof option === "string" ? { target: option } : option
|
|
42
|
+
});
|
|
76
43
|
return total;
|
|
77
44
|
},
|
|
78
45
|
[]
|
|
@@ -92,7 +59,7 @@ const createProxyHandler = (proxyOptions) => {
|
|
|
92
59
|
const formattedProxy = formatProxyOptions(proxyOptions);
|
|
93
60
|
const middlewares = formattedProxy.map((option) => {
|
|
94
61
|
const middleware = (0, import_http_proxy_middleware.createProxyMiddleware)(option.context, option);
|
|
95
|
-
return (ctx, next) =>
|
|
62
|
+
return async (ctx, next) => {
|
|
96
63
|
const { req, res } = ctx;
|
|
97
64
|
const bypassUrl = typeof option.bypass === "function" ? option.bypass(req, res, option) : null;
|
|
98
65
|
if (typeof bypassUrl === "boolean") {
|
|
@@ -103,7 +70,7 @@ const createProxyHandler = (proxyOptions) => {
|
|
|
103
70
|
return next();
|
|
104
71
|
}
|
|
105
72
|
middleware(req, res, next);
|
|
106
|
-
}
|
|
73
|
+
};
|
|
107
74
|
});
|
|
108
75
|
return middlewares;
|
|
109
76
|
};
|
|
@@ -16,26 +16,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
16
16
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
17
|
mod
|
|
18
18
|
));
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
19
|
var import_url = __toESM(require("url"));
|
|
40
20
|
var import_spr = require("../spr");
|
|
41
21
|
var import_util = require("../util");
|
|
@@ -74,28 +54,26 @@ describe("test spr util functions", () => {
|
|
|
74
54
|
`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`
|
|
75
55
|
);
|
|
76
56
|
});
|
|
77
|
-
it("should only invoke func one time", () =>
|
|
57
|
+
it("should only invoke func one time", async () => {
|
|
78
58
|
let index = 0;
|
|
79
59
|
const fn = (0, import_util.withCoalescedInvoke)(
|
|
80
|
-
() =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}, 500);
|
|
86
|
-
});
|
|
60
|
+
async () => new Promise((resolve) => {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
index += 1;
|
|
63
|
+
resolve(index);
|
|
64
|
+
}, 500);
|
|
87
65
|
})
|
|
88
66
|
);
|
|
89
67
|
const key = "test";
|
|
90
|
-
const [res1, res2] =
|
|
68
|
+
const [res1, res2] = await Promise.all([fn(key, []), fn(key, [])]);
|
|
91
69
|
expect(res1.isOrigin && res2.isOrigin).toBe(false);
|
|
92
70
|
expect(res1.isOrigin || res2.isOrigin).toBe(true);
|
|
93
71
|
expect(res1.value).toBe(1);
|
|
94
72
|
expect(res2.value).toBe(1);
|
|
95
|
-
})
|
|
96
|
-
it("should invoke sync or async", () =>
|
|
73
|
+
});
|
|
74
|
+
it("should invoke sync or async", async () => {
|
|
97
75
|
const foo = "";
|
|
98
|
-
const async =
|
|
76
|
+
const async = await (0, import_util.maybeSync)(
|
|
99
77
|
() => new Promise((resolve) => {
|
|
100
78
|
setTimeout(() => {
|
|
101
79
|
resolve(foo);
|
|
@@ -103,7 +81,7 @@ describe("test spr util functions", () => {
|
|
|
103
81
|
})
|
|
104
82
|
)(false);
|
|
105
83
|
expect(async).toBeUndefined();
|
|
106
|
-
const sync =
|
|
84
|
+
const sync = await (0, import_util.maybeSync)(
|
|
107
85
|
() => new Promise((resolve) => {
|
|
108
86
|
setTimeout(() => {
|
|
109
87
|
resolve(foo);
|
|
@@ -111,5 +89,5 @@ describe("test spr util functions", () => {
|
|
|
111
89
|
})
|
|
112
90
|
)(true);
|
|
113
91
|
expect(sync).toBe(foo);
|
|
114
|
-
})
|
|
92
|
+
});
|
|
115
93
|
});
|
|
@@ -1,55 +1,20 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
1
|
var import_spr = require("../spr");
|
|
38
2
|
var import_error_configuration = require("./error-configuration");
|
|
39
3
|
var import_cacheable = require("./cacheable");
|
|
40
4
|
var import_matched_cache = require("./matched-cache");
|
|
41
|
-
const createCacheConfig = (config = {}) =>
|
|
5
|
+
const createCacheConfig = (config = {}) => ({
|
|
42
6
|
excludes: null,
|
|
43
7
|
includes: null,
|
|
44
8
|
interval: 10,
|
|
45
9
|
staleLimit: false,
|
|
46
10
|
level: 0,
|
|
47
11
|
fallback: false,
|
|
48
|
-
matches: null
|
|
49
|
-
|
|
12
|
+
matches: null,
|
|
13
|
+
...config
|
|
14
|
+
});
|
|
50
15
|
jest.setTimeout(6e4);
|
|
51
16
|
describe("cache", () => {
|
|
52
|
-
it("should cache correctly", () =>
|
|
17
|
+
it("should cache correctly", async () => {
|
|
53
18
|
(0, import_spr.destroyCache)();
|
|
54
19
|
const cache = (0, import_spr.createCache)();
|
|
55
20
|
const context = {
|
|
@@ -60,12 +25,12 @@ describe("cache", () => {
|
|
|
60
25
|
};
|
|
61
26
|
const content = "hello";
|
|
62
27
|
const cacheConfig = createCacheConfig();
|
|
63
|
-
|
|
64
|
-
const cacheResult =
|
|
28
|
+
await cache.set(context, content, cacheConfig, true);
|
|
29
|
+
const cacheResult = await cache.get(context);
|
|
65
30
|
expect(cacheResult).not.toBe(null);
|
|
66
31
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe("hello");
|
|
67
|
-
})
|
|
68
|
-
it("should ignore cache set when cache config not exist", () =>
|
|
32
|
+
});
|
|
33
|
+
it("should ignore cache set when cache config not exist", async () => {
|
|
69
34
|
(0, import_spr.destroyCache)();
|
|
70
35
|
(0, import_spr.destroyCache)();
|
|
71
36
|
const cache = (0, import_spr.createCache)();
|
|
@@ -76,10 +41,10 @@ describe("cache", () => {
|
|
|
76
41
|
headers: {}
|
|
77
42
|
};
|
|
78
43
|
const content = "hello";
|
|
79
|
-
const shouldCache =
|
|
44
|
+
const shouldCache = await cache.set(context, content, null, true);
|
|
80
45
|
expect(shouldCache).toBe(false);
|
|
81
|
-
})
|
|
82
|
-
it("should calcual cache key error", () =>
|
|
46
|
+
});
|
|
47
|
+
it("should calcual cache key error", async () => {
|
|
83
48
|
(0, import_spr.destroyCache)();
|
|
84
49
|
const cache = (0, import_spr.createCache)();
|
|
85
50
|
const content = "hello";
|
|
@@ -92,11 +57,11 @@ describe("cache", () => {
|
|
|
92
57
|
query: {},
|
|
93
58
|
headers: {}
|
|
94
59
|
};
|
|
95
|
-
const shouldCache =
|
|
60
|
+
const shouldCache = await cache.set(context, content, cacheConfig);
|
|
96
61
|
expect(shouldCache).toBe(false);
|
|
97
62
|
}
|
|
98
|
-
})
|
|
99
|
-
it("should get nothing for diff requestKey", () =>
|
|
63
|
+
});
|
|
64
|
+
it("should get nothing for diff requestKey", async () => {
|
|
100
65
|
(0, import_spr.destroyCache)();
|
|
101
66
|
const cache = (0, import_spr.createCache)();
|
|
102
67
|
const context = {
|
|
@@ -110,17 +75,17 @@ describe("cache", () => {
|
|
|
110
75
|
level: 1,
|
|
111
76
|
includes: { query: ["name"] }
|
|
112
77
|
});
|
|
113
|
-
|
|
78
|
+
await cache.set(context, content, cacheConfig, true);
|
|
114
79
|
const context_req = {
|
|
115
80
|
entry: "",
|
|
116
81
|
pathname: "/home",
|
|
117
82
|
query: {},
|
|
118
83
|
headers: {}
|
|
119
84
|
};
|
|
120
|
-
const cacheResult =
|
|
85
|
+
const cacheResult = await cache.get(context_req);
|
|
121
86
|
expect(cacheResult).toBe(null);
|
|
122
|
-
})
|
|
123
|
-
it("should get nothing for diff cacheHash", () =>
|
|
87
|
+
});
|
|
88
|
+
it("should get nothing for diff cacheHash", async () => {
|
|
124
89
|
(0, import_spr.destroyCache)();
|
|
125
90
|
const cache = (0, import_spr.createCache)();
|
|
126
91
|
const context = {
|
|
@@ -134,17 +99,17 @@ describe("cache", () => {
|
|
|
134
99
|
level: 1,
|
|
135
100
|
includes: { query: ["name"] }
|
|
136
101
|
});
|
|
137
|
-
|
|
102
|
+
await cache.set(context, content, cacheConfig, true);
|
|
138
103
|
const context_req = {
|
|
139
104
|
entry: "",
|
|
140
105
|
pathname: "",
|
|
141
106
|
query: { name: "zll" },
|
|
142
107
|
headers: {}
|
|
143
108
|
};
|
|
144
|
-
const cacheResult =
|
|
109
|
+
const cacheResult = await cache.get(context_req);
|
|
145
110
|
expect(cacheResult).toBe(null);
|
|
146
|
-
})
|
|
147
|
-
it("should get cache correctly", () =>
|
|
111
|
+
});
|
|
112
|
+
it("should get cache correctly", async () => {
|
|
148
113
|
(0, import_spr.destroyCache)();
|
|
149
114
|
const cache = (0, import_spr.createCache)();
|
|
150
115
|
for (const cacheable of import_cacheable.cacheabelAry) {
|
|
@@ -155,12 +120,12 @@ describe("cache", () => {
|
|
|
155
120
|
headers: cacheable.requestOpt.headers || {}
|
|
156
121
|
};
|
|
157
122
|
const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
|
|
158
|
-
|
|
159
|
-
const cacheResult =
|
|
123
|
+
await cache.set(context, cacheable.content, cacheConfig, true);
|
|
124
|
+
const cacheResult = await cache.get(context);
|
|
160
125
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(cacheable.content);
|
|
161
126
|
}
|
|
162
|
-
})
|
|
163
|
-
it("should match cache correctly", () =>
|
|
127
|
+
});
|
|
128
|
+
it("should match cache correctly", async () => {
|
|
164
129
|
(0, import_spr.destroyCache)();
|
|
165
130
|
const cache = (0, import_spr.createCache)();
|
|
166
131
|
for (const cacheable of import_matched_cache.matchedCacheableAry) {
|
|
@@ -172,14 +137,14 @@ describe("cache", () => {
|
|
|
172
137
|
query: requestOpt.query,
|
|
173
138
|
headers: requestOpt.headers
|
|
174
139
|
};
|
|
175
|
-
|
|
140
|
+
await cache.set(context, content, createCacheConfig(cacheConfig), true);
|
|
176
141
|
const matchContext = {
|
|
177
142
|
entry: "",
|
|
178
143
|
pathname: matchOne.url,
|
|
179
144
|
query: matchOne.query,
|
|
180
145
|
headers: matchOne.headers
|
|
181
146
|
};
|
|
182
|
-
const cacheResult =
|
|
147
|
+
const cacheResult = await cache.get(matchContext);
|
|
183
148
|
expect(cacheResult == null ? void 0 : cacheResult.content).toBe(content);
|
|
184
149
|
for (const notMatch of other) {
|
|
185
150
|
const notMatchContext = {
|
|
@@ -188,12 +153,12 @@ describe("cache", () => {
|
|
|
188
153
|
query: notMatch.query,
|
|
189
154
|
headers: notMatch.headers
|
|
190
155
|
};
|
|
191
|
-
const nothing =
|
|
156
|
+
const nothing = await cache.get(notMatchContext);
|
|
192
157
|
expect(nothing).toBe(null);
|
|
193
158
|
}
|
|
194
159
|
}
|
|
195
|
-
})
|
|
196
|
-
it("should stale cache correctly", () =>
|
|
160
|
+
});
|
|
161
|
+
it("should stale cache correctly", async () => {
|
|
197
162
|
(0, import_spr.destroyCache)();
|
|
198
163
|
const cache = (0, import_spr.createCache)();
|
|
199
164
|
const context = {
|
|
@@ -204,19 +169,19 @@ describe("cache", () => {
|
|
|
204
169
|
};
|
|
205
170
|
const config = createCacheConfig({ interval: 5 });
|
|
206
171
|
const content = "hello";
|
|
207
|
-
const shouldCache =
|
|
172
|
+
const shouldCache = await cache.set(context, content, config, true);
|
|
208
173
|
expect(shouldCache.value).toBe(true);
|
|
209
|
-
const freshResult =
|
|
174
|
+
const freshResult = await cache.get(context);
|
|
210
175
|
expect(freshResult == null ? void 0 : freshResult.isStale).toBe(false);
|
|
211
|
-
|
|
176
|
+
await new Promise((resolve) => {
|
|
212
177
|
setTimeout(() => {
|
|
213
178
|
resolve();
|
|
214
179
|
}, 6e3);
|
|
215
180
|
});
|
|
216
|
-
const staleResult =
|
|
181
|
+
const staleResult = await cache.get(context);
|
|
217
182
|
expect(staleResult == null ? void 0 : staleResult.isStale).toBe(true);
|
|
218
|
-
})
|
|
219
|
-
it("should garbage cache correctly", () =>
|
|
183
|
+
});
|
|
184
|
+
it("should garbage cache correctly", async () => {
|
|
220
185
|
(0, import_spr.destroyCache)();
|
|
221
186
|
const cache = (0, import_spr.createCache)();
|
|
222
187
|
const context = {
|
|
@@ -230,16 +195,16 @@ describe("cache", () => {
|
|
|
230
195
|
staleLimit: 8
|
|
231
196
|
});
|
|
232
197
|
const content = "hello";
|
|
233
|
-
const shouldCache =
|
|
198
|
+
const shouldCache = await cache.set(context, content, config, true);
|
|
234
199
|
expect(shouldCache.value).toBe(true);
|
|
235
|
-
const freshResult =
|
|
200
|
+
const freshResult = await cache.get(context);
|
|
236
201
|
expect(freshResult == null ? void 0 : freshResult.isGarbage).toBe(false);
|
|
237
|
-
|
|
202
|
+
await new Promise((resolve) => {
|
|
238
203
|
setTimeout(() => {
|
|
239
204
|
resolve();
|
|
240
205
|
}, 1e4);
|
|
241
206
|
});
|
|
242
|
-
const staleResult =
|
|
207
|
+
const staleResult = await cache.get(context);
|
|
243
208
|
expect(staleResult == null ? void 0 : staleResult.isGarbage).toBe(true);
|
|
244
|
-
})
|
|
209
|
+
});
|
|
245
210
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|