@modern-js/prod-server 2.0.0-beta.3 → 2.0.0-beta.6
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 +139 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +44 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +150 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +384 -422
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +53 -30
- package/dist/js/node/index.js +37 -57
- package/dist/js/node/libs/context/context.js +83 -94
- package/dist/js/node/libs/context/index.js +28 -13
- package/dist/js/node/libs/hook-api/index.js +76 -48
- package/dist/js/node/libs/hook-api/route.js +26 -11
- package/dist/js/node/libs/hook-api/template.js +41 -39
- package/dist/js/node/libs/loadConfig.js +73 -35
- package/dist/js/node/libs/metrics.js +25 -9
- package/dist/js/node/libs/proxy.js +89 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +99 -56
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +147 -128
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +65 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +58 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +105 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +54 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +33 -12
- package/dist/js/node/libs/render/cache/spr.js +161 -129
- package/dist/js/node/libs/render/cache/type.js +15 -5
- package/dist/js/node/libs/render/cache/util.js +99 -45
- package/dist/js/node/libs/render/index.js +106 -67
- package/dist/js/node/libs/render/measure.js +58 -31
- package/dist/js/node/libs/render/reader.js +95 -70
- package/dist/js/node/libs/render/ssr.js +80 -47
- package/dist/js/node/libs/render/static.js +79 -40
- package/dist/js/node/libs/render/type.js +31 -12
- package/dist/js/node/libs/route/index.js +31 -26
- package/dist/js/node/libs/route/matcher.js +40 -41
- package/dist/js/node/libs/route/route.js +29 -22
- package/dist/js/node/libs/serve-file.js +66 -32
- package/dist/js/node/server/index.js +168 -160
- package/dist/js/node/server/modern-server-split.js +72 -22
- package/dist/js/node/server/modern-server.js +403 -445
- package/dist/js/node/type.js +15 -3
- package/dist/js/node/utils.js +85 -52
- package/dist/js/node/worker-server.js +57 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +267 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +493 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1048 -909
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
@@ -1,90 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithoutHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
8
|
+
}
|
|
9
|
+
function _defineProperty(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterableToArray(iter) {
|
|
23
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
|
+
}
|
|
25
|
+
function _nonIterableSpread() {
|
|
26
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
27
|
+
}
|
|
28
|
+
function _objectSpread(target) {
|
|
29
|
+
for(var i = 1; i < arguments.length; i++){
|
|
30
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
31
|
+
var ownKeys = Object.keys(source);
|
|
32
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
33
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
34
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
ownKeys.forEach(function(key) {
|
|
38
|
+
_defineProperty(target, key, source[key]);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
function _toConsumableArray(arr) {
|
|
44
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
45
|
+
}
|
|
46
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
47
|
+
if (!o) return;
|
|
48
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
49
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
50
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
51
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
52
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
53
|
+
}
|
|
54
|
+
import { createDebugger, isProd } from "@modern-js/utils";
|
|
55
|
+
var debug = createDebugger("prod-server");
|
|
56
|
+
var mergeExtension = function(users) {
|
|
57
|
+
var output = [];
|
|
58
|
+
return {
|
|
59
|
+
middleware: output.concat(users)
|
|
60
|
+
};
|
|
13
61
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
62
|
+
var noop = function() {};
|
|
63
|
+
var createErrorDocument = function(status, text) {
|
|
64
|
+
var title = "".concat(status, ": ").concat(text);
|
|
65
|
+
return '<!DOCTYPE html>\n <html lang="en">\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width">\n <title>'.concat(title, '</title>\n <style>\n html,body {\n margin: 0;\n }\n\n .page-container {\n color: #000;\n background: #fff;\n height: 100vh;\n text-align: center;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n </style>\n </head>\n <body>\n <div class="page-container">\n <h1>').concat(status, "</h1>\n <div>").concat(text, "</div>\n </body>\n </html>\n ");
|
|
17
66
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
67
|
+
var createMiddlewareCollecter = function() {
|
|
68
|
+
var webMiddlewares = [];
|
|
69
|
+
var apiMiddlewares = [];
|
|
70
|
+
var addWebMiddleware = function(input) {
|
|
71
|
+
webMiddlewares.push(input);
|
|
72
|
+
};
|
|
73
|
+
var addAPIMiddleware = function(input) {
|
|
74
|
+
apiMiddlewares.push(input);
|
|
75
|
+
};
|
|
76
|
+
var getMiddlewares = function() {
|
|
77
|
+
return {
|
|
78
|
+
web: webMiddlewares,
|
|
79
|
+
api: apiMiddlewares
|
|
80
|
+
};
|
|
81
|
+
};
|
|
28
82
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
83
|
+
getMiddlewares: getMiddlewares,
|
|
84
|
+
addWebMiddleware: addWebMiddleware,
|
|
85
|
+
addAPIMiddleware: addAPIMiddleware
|
|
31
86
|
};
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
getMiddlewares: getMiddlewares,
|
|
35
|
-
addWebMiddleware: addWebMiddleware,
|
|
36
|
-
addAPIMiddleware: addAPIMiddleware
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export var useLocalPrefix = function useLocalPrefix(url) {
|
|
40
|
-
return isProd() && !url.includes('.');
|
|
41
87
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var html = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
45
|
-
var _output$distPath = output.distPath;
|
|
46
|
-
_output$distPath = _output$distPath === void 0 ? {} : _output$distPath;
|
|
47
|
-
var cssPath = _output$distPath.css,
|
|
48
|
-
jsPath = _output$distPath.js,
|
|
49
|
-
mediaPath = _output$distPath.media,
|
|
50
|
-
_output$assetPrefix = output.assetPrefix,
|
|
51
|
-
assetPrefix = _output$assetPrefix === void 0 ? '/' : _output$assetPrefix;
|
|
52
|
-
var favicon = html.favicon,
|
|
53
|
-
faviconByEntries = html.faviconByEntries;
|
|
54
|
-
var prefix = useLocalPrefix(assetPrefix) ? assetPrefix : '';
|
|
55
|
-
var favicons = prepareFavicons(favicon, faviconByEntries);
|
|
56
|
-
var staticFiles = [cssPath, jsPath, mediaPath].filter(function (v) {
|
|
57
|
-
return Boolean(v);
|
|
58
|
-
});
|
|
59
|
-
var staticReg = ['static/', 'upload/'].concat(_toConsumableArray(staticFiles));
|
|
60
|
-
var iconReg = ['favicon.ico', 'icon.png'].concat(_toConsumableArray(favicons));
|
|
61
|
-
var regPrefix = prefix.endsWith('/') ? prefix : "".concat(prefix, "/");
|
|
62
|
-
var staticPathRegExp = new RegExp("^".concat(regPrefix, "(").concat([].concat(_toConsumableArray(staticReg), _toConsumableArray(iconReg)).join('|'), ")"));
|
|
63
|
-
return staticPathRegExp;
|
|
88
|
+
var useLocalPrefix = function(url) {
|
|
89
|
+
return isProd() && !url.includes(".");
|
|
64
90
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
var getStaticReg = function() {
|
|
92
|
+
var output = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, html = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
93
|
+
var tmp = output.distPath, ref = tmp === void 0 ? {} : tmp, cssPath = ref.css, jsPath = ref.js, mediaPath = ref.media, _assetPrefix = output.assetPrefix, assetPrefix = _assetPrefix === void 0 ? "/" : _assetPrefix;
|
|
94
|
+
var favicon = html.favicon, faviconByEntries = html.faviconByEntries;
|
|
95
|
+
var prefix = useLocalPrefix(assetPrefix) ? assetPrefix : "";
|
|
96
|
+
var favicons = prepareFavicons(favicon, faviconByEntries);
|
|
97
|
+
var staticFiles = [
|
|
98
|
+
cssPath,
|
|
99
|
+
jsPath,
|
|
100
|
+
mediaPath
|
|
101
|
+
].filter(function(v) {
|
|
102
|
+
return Boolean(v);
|
|
76
103
|
});
|
|
77
|
-
|
|
78
|
-
|
|
104
|
+
var staticReg = [
|
|
105
|
+
"static/",
|
|
106
|
+
"upload/"
|
|
107
|
+
].concat(_toConsumableArray(staticFiles));
|
|
108
|
+
var iconReg = [
|
|
109
|
+
"favicon.ico",
|
|
110
|
+
"icon.png"
|
|
111
|
+
].concat(_toConsumableArray(favicons));
|
|
112
|
+
var regPrefix = prefix.endsWith("/") ? prefix : "".concat(prefix, "/");
|
|
113
|
+
var staticPathRegExp = new RegExp("^".concat(regPrefix, "(").concat(_toConsumableArray(staticReg).concat(_toConsumableArray(iconReg)).join("|"), ")"));
|
|
114
|
+
return staticPathRegExp;
|
|
115
|
+
};
|
|
116
|
+
var prepareFavicons = function(favicon, faviconByEntries) {
|
|
117
|
+
var faviconNames = [];
|
|
118
|
+
if (favicon) {
|
|
119
|
+
faviconNames.push(favicon.substring(favicon.lastIndexOf("/") + 1));
|
|
120
|
+
}
|
|
121
|
+
if (faviconByEntries) {
|
|
122
|
+
Object.keys(faviconByEntries).forEach(function(f) {
|
|
123
|
+
var curFavicon = faviconByEntries[f];
|
|
124
|
+
if (curFavicon) {
|
|
125
|
+
faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf("/") + 1));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return faviconNames;
|
|
130
|
+
};
|
|
131
|
+
var headersWithoutCookie = function(headers) {
|
|
132
|
+
if (typeof headers.cookie !== "undefined") {
|
|
133
|
+
var safeHeaders = _objectSpread({}, headers);
|
|
134
|
+
delete safeHeaders.cookie;
|
|
135
|
+
return safeHeaders;
|
|
136
|
+
}
|
|
137
|
+
return headers;
|
|
79
138
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
139
|
+
var isRedirect = function(code) {
|
|
140
|
+
return [
|
|
141
|
+
301,
|
|
142
|
+
302,
|
|
143
|
+
307,
|
|
144
|
+
308
|
|
145
|
+
].includes(code);
|
|
87
146
|
};
|
|
88
|
-
export
|
|
89
|
-
return [301, 302, 307, 308].includes(code);
|
|
90
|
-
};
|
|
147
|
+
export { createErrorDocument, createMiddlewareCollecter, debug, getStaticReg, headersWithoutCookie, isRedirect, mergeExtension, noop, prepareFavicons, useLocalPrefix };
|
|
@@ -1,56 +1,177 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
res: ctx.response,
|
|
40
|
-
params: ctx.params || params || {}
|
|
41
|
-
});
|
|
42
|
-
case 12:
|
|
43
|
-
ctx.body = _context.sent;
|
|
44
|
-
ctx.status = 200;
|
|
45
|
-
case 14:
|
|
46
|
-
case "end":
|
|
47
|
-
return _context.stop();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, _callee);
|
|
51
|
-
}));
|
|
52
|
-
return function (_x) {
|
|
53
|
-
return _ref.apply(this, arguments);
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
54
39
|
};
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
return(g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g);
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var _request, _request1, _request2;
|
|
126
|
+
import { RouteMatchManager } from "./libs/route";
|
|
127
|
+
var createHandler = function(manifest) {
|
|
128
|
+
var routeMgr = new RouteMatchManager();
|
|
129
|
+
var pages = manifest.pages, routes = manifest.routes;
|
|
130
|
+
routeMgr.reset(routes);
|
|
131
|
+
return function() {
|
|
132
|
+
var _ref = _asyncToGenerator(function(ctx) {
|
|
133
|
+
var pageMatch, page, _query, _pathname, _params, params;
|
|
134
|
+
return __generator(this, function(_state) {
|
|
135
|
+
switch(_state.label){
|
|
136
|
+
case 0:
|
|
137
|
+
pageMatch = routeMgr.match(ctx.url);
|
|
138
|
+
if (!pageMatch) {
|
|
139
|
+
ctx.body = "404: Page not found";
|
|
140
|
+
ctx.status = 404;
|
|
141
|
+
return [
|
|
142
|
+
2
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
page = pages[pageMatch.spec.urlPath];
|
|
146
|
+
(_query = (_request = ctx.request).query) !== null && _query !== void 0 ? _query : _request.query = ctx.query;
|
|
147
|
+
(_pathname = (_request1 = ctx.request).pathname) !== null && _pathname !== void 0 ? _pathname : _request1.pathname = ctx.pathname;
|
|
148
|
+
(_params = (_request2 = ctx.request).params) !== null && _params !== void 0 ? _params : _request2.params = ctx.params;
|
|
149
|
+
params = pageMatch.parseURLParams(ctx.url);
|
|
150
|
+
return [
|
|
151
|
+
4,
|
|
152
|
+
page.serverRender({
|
|
153
|
+
template: page.template,
|
|
154
|
+
query: ctx.query,
|
|
155
|
+
request: ctx.request,
|
|
156
|
+
response: ctx.response,
|
|
157
|
+
pathname: ctx.pathname,
|
|
158
|
+
req: ctx.request,
|
|
159
|
+
res: ctx.response,
|
|
160
|
+
params: ctx.params || params || {}
|
|
161
|
+
})
|
|
162
|
+
];
|
|
163
|
+
case 1:
|
|
164
|
+
ctx.body = _state.sent();
|
|
165
|
+
ctx.status = 200;
|
|
166
|
+
return [
|
|
167
|
+
2
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return function(ctx) {
|
|
173
|
+
return _ref.apply(this, arguments);
|
|
174
|
+
};
|
|
175
|
+
}();
|
|
176
|
+
};
|
|
177
|
+
export { createHandler };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export { ModernServer } from './server/modern-server';
|
|
|
6
6
|
export { createProxyHandler } from './libs/proxy';
|
|
7
7
|
export * from './type';
|
|
8
8
|
export * from './constants';
|
|
9
|
+
|
|
9
10
|
declare const _default: (options: ModernServerOptions) => Promise<Server>;
|
|
11
|
+
|
|
10
12
|
export default _default;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference path="../../type.d.ts" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
2
|
/// <reference types="node" />
|
|
4
3
|
/// <reference types="node" />
|
|
5
4
|
/// <reference types="node" />
|
|
6
5
|
/// <reference types="node/http" />
|
|
6
|
+
/// <reference types=".dts-temp/kvE-lN6mJShspqSQDC8Aw/src/type" />
|
|
7
7
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
8
8
|
import { URL } from 'url';
|
|
9
9
|
import qs from 'querystring';
|
|
@@ -20,10 +20,12 @@ export declare class ModernServerContext implements ModernServerContextInterface
|
|
|
20
20
|
/**
|
|
21
21
|
* http response
|
|
22
22
|
*/
|
|
23
|
+
|
|
23
24
|
res: ServerResponse;
|
|
24
25
|
/**
|
|
25
26
|
* url params
|
|
26
27
|
*/
|
|
28
|
+
|
|
27
29
|
params: Record<string, string>;
|
|
28
30
|
get logger(): import("@modern-js/types").Logger;
|
|
29
31
|
get metrics(): import("@modern-js/types").Metrics;
|
|
@@ -54,6 +56,7 @@ export declare class ModernServerContext implements ModernServerContextInterface
|
|
|
54
56
|
/**
|
|
55
57
|
* 判断链接是否已经关闭
|
|
56
58
|
*/
|
|
59
|
+
|
|
57
60
|
resHasHandled(): boolean;
|
|
58
61
|
error(dig: string, e?: Error | string): void;
|
|
59
62
|
}
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import type { ModernServerContext } from '@modern-js/types';
|
|
4
4
|
import { RenderFunction, SSRServerContext } from '../type';
|
|
5
|
+
|
|
5
6
|
declare const _default: (renderFn: RenderFunction, ctx: ModernServerContext) => (context: SSRServerContext) => Promise<string | Readable>;
|
|
7
|
+
|
|
6
8
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import LRUCache from 'lru-cache';
|
|
2
2
|
import { CacheContent, CacheManagerOptions, CacheResult, CacheContext, CacheConfig } from './type';
|
|
3
|
+
|
|
3
4
|
declare class CacheManager {
|
|
4
5
|
cache: LRUCache<string, CacheContent>;
|
|
5
6
|
cacheOptions: CacheManagerOptions;
|
|
@@ -17,6 +18,7 @@ declare class CacheManager {
|
|
|
17
18
|
set(context: CacheContext, html: string, cacheConfig: CacheConfig, sync?: boolean): Promise<any>;
|
|
18
19
|
del(context: CacheContext, cacheHash: string): Promise<void>;
|
|
19
20
|
}
|
|
21
|
+
|
|
20
22
|
export declare function createCache(): CacheManager;
|
|
21
23
|
export declare function destroyCache(): void;
|
|
22
24
|
export {};
|
|
@@ -8,7 +8,6 @@ export declare class ModernRoute implements ModernRouteInterface {
|
|
|
8
8
|
isApi: boolean;
|
|
9
9
|
isSSR: boolean;
|
|
10
10
|
isSPA: boolean;
|
|
11
|
-
enableModernMode?: boolean;
|
|
12
11
|
params: Record<string, any>;
|
|
13
12
|
responseHeaders?: Record<string, any>;
|
|
14
13
|
constructor(routeSpec: ModernRouteInterface);
|
|
@@ -25,12 +25,14 @@ export declare class Server {
|
|
|
25
25
|
* - 执行 prepare hook
|
|
26
26
|
* - 执行 server init
|
|
27
27
|
*/
|
|
28
|
+
|
|
28
29
|
init(): Promise<this>;
|
|
29
30
|
/**
|
|
30
31
|
* Execute config hooks
|
|
31
32
|
* @param runner
|
|
32
33
|
* @param options
|
|
33
34
|
*/
|
|
35
|
+
|
|
34
36
|
private runConfigHook;
|
|
35
37
|
private runPrepareHook;
|
|
36
38
|
private initServerConfig;
|
|
@@ -38,6 +40,7 @@ export declare class Server {
|
|
|
38
40
|
*
|
|
39
41
|
* merge cliConfig and serverConfig
|
|
40
42
|
*/
|
|
43
|
+
|
|
41
44
|
private initConfig;
|
|
42
45
|
close(): Promise<void>;
|
|
43
46
|
listen<T extends number | ListenOptions | undefined>(options: T, listener: any): void;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/// <reference path="type.d.ts" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
2
|
/// <reference types="node/http" />
|
|
3
|
+
/// <reference types=".dts-temp/kvE-lN6mJShspqSQDC8Aw/src/type" />
|
|
4
4
|
import { IncomingMessage } from 'http';
|
|
5
5
|
import type { OutputNormalizedConfig, HtmlNormalizedConfig } from '@modern-js/server-core';
|
|
6
6
|
export declare const debug: any;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -46,11 +46,9 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@babel/compat-data": "^7.17.10",
|
|
50
49
|
"axios": "^0.24.0",
|
|
51
50
|
"etag": "^1.8.1",
|
|
52
51
|
"fresh": "^0.5.2",
|
|
53
|
-
"compare-versions": "^3.6.0",
|
|
54
52
|
"cookie": "^0.4.2",
|
|
55
53
|
"http-proxy-middleware": "^2.0.1",
|
|
56
54
|
"ignore-styles": "^5.0.1",
|
|
@@ -58,9 +56,8 @@
|
|
|
58
56
|
"merge-deep": "^3.0.3",
|
|
59
57
|
"path-to-regexp": "^6.2.0",
|
|
60
58
|
"serve-static": "^1.14.1",
|
|
61
|
-
"
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@modern-js/server-core": "2.0.0-beta.3"
|
|
59
|
+
"@modern-js/utils": "2.0.0-beta.6",
|
|
60
|
+
"@modern-js/server-core": "2.0.0-beta.6"
|
|
64
61
|
},
|
|
65
62
|
"devDependencies": {
|
|
66
63
|
"@types/cookie": "^0.4.1",
|
|
@@ -71,20 +68,16 @@
|
|
|
71
68
|
"@types/etag": "^1.8.1",
|
|
72
69
|
"@types/fresh": "^0.5.0",
|
|
73
70
|
"@types/serve-static": "^1.13.10",
|
|
74
|
-
"@types/ua-parser-js": "^0.7.36",
|
|
75
71
|
"jest": "^27",
|
|
76
72
|
"node-mocks-http": "^1.11.0",
|
|
77
73
|
"portfinder": "^1.0.28",
|
|
78
74
|
"typescript": "^4",
|
|
79
|
-
"@modern-js/types": "2.0.0-beta.
|
|
80
|
-
"@modern-js/server-core": "2.0.0-beta.
|
|
81
|
-
"@scripts/
|
|
82
|
-
"@scripts/
|
|
75
|
+
"@modern-js/types": "2.0.0-beta.6",
|
|
76
|
+
"@modern-js/server-core": "2.0.0-beta.6",
|
|
77
|
+
"@scripts/build": "2.0.0-beta.6",
|
|
78
|
+
"@scripts/jest-config": "2.0.0-beta.6"
|
|
83
79
|
},
|
|
84
80
|
"sideEffects": false,
|
|
85
|
-
"modernConfig": {
|
|
86
|
-
"output": {}
|
|
87
|
-
},
|
|
88
81
|
"publishConfig": {
|
|
89
82
|
"access": "public",
|
|
90
83
|
"registry": "https://registry.npmjs.org/"
|