@modern-js/prod-server 2.9.0 → 2.9.1-alpha.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/dist/cjs/server/index.js +8 -6
- package/dist/esm/server/index.js +71 -18
- package/dist/esm-node/server/index.js +9 -6
- package/dist/js/modern/constants.js +35 -0
- package/dist/js/modern/index.js +18 -0
- package/dist/js/modern/libs/context/context.js +160 -0
- package/dist/js/modern/libs/context/index.js +6 -0
- package/dist/js/modern/libs/hook-api/index.js +134 -0
- package/dist/js/modern/libs/hook-api/route.js +20 -0
- package/dist/js/modern/libs/hook-api/template.js +73 -0
- package/dist/js/modern/libs/loadConfig.js +62 -0
- package/dist/js/modern/libs/logger.js +111 -0
- package/dist/js/modern/libs/metrics.js +11 -0
- package/dist/js/modern/libs/proxy.js +92 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +114 -0
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +254 -0
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +47 -0
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +37 -0
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +91 -0
- package/dist/js/modern/libs/render/cache/index.js +115 -0
- package/dist/js/modern/libs/render/cache/page-caches/index.js +32 -0
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +29 -0
- package/dist/js/modern/libs/render/cache/spr.js +248 -0
- package/dist/js/modern/libs/render/cache/type.js +0 -0
- package/dist/js/modern/libs/render/cache/util.js +102 -0
- package/dist/js/modern/libs/render/index.js +86 -0
- package/dist/js/modern/libs/render/measure.js +68 -0
- package/dist/js/modern/libs/render/reader.js +107 -0
- package/dist/js/modern/libs/render/ssr.js +100 -0
- package/dist/js/modern/libs/render/static.js +60 -0
- package/dist/js/modern/libs/render/type.js +9 -0
- package/dist/js/modern/libs/route/index.js +54 -0
- package/dist/js/modern/libs/route/matcher.js +87 -0
- package/dist/js/modern/libs/route/route.js +16 -0
- package/dist/js/modern/libs/serve-file.js +67 -0
- package/dist/js/modern/server/index.js +208 -0
- package/dist/js/modern/server/modern-server-split.js +74 -0
- package/dist/js/modern/server/modern-server.js +554 -0
- package/dist/js/modern/type.js +0 -0
- package/dist/js/modern/utils.js +136 -0
- package/dist/js/modern/worker-server.js +89 -0
- package/dist/js/node/constants.js +62 -0
- package/dist/js/node/index.js +44 -0
- package/dist/js/node/libs/context/context.js +189 -0
- package/dist/js/node/libs/context/index.js +30 -0
- package/dist/js/node/libs/hook-api/index.js +164 -0
- package/dist/js/node/libs/hook-api/route.js +43 -0
- package/dist/js/node/libs/hook-api/template.js +97 -0
- package/dist/js/node/libs/loadConfig.js +91 -0
- package/dist/js/node/libs/logger.js +133 -0
- package/dist/js/node/libs/metrics.js +34 -0
- package/dist/js/node/libs/proxy.js +114 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +115 -0
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +245 -0
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +70 -0
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +60 -0
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +114 -0
- package/dist/js/node/libs/render/cache/index.js +134 -0
- package/dist/js/node/libs/render/cache/page-caches/index.js +55 -0
- package/dist/js/node/libs/render/cache/page-caches/lru.js +58 -0
- package/dist/js/node/libs/render/cache/spr.js +270 -0
- package/dist/js/node/libs/render/cache/type.js +15 -0
- package/dist/js/node/libs/render/cache/util.js +138 -0
- package/dist/js/node/libs/render/index.js +115 -0
- package/dist/js/node/libs/render/measure.js +90 -0
- package/dist/js/node/libs/render/reader.js +140 -0
- package/dist/js/node/libs/render/ssr.js +123 -0
- package/dist/js/node/libs/render/static.js +89 -0
- package/dist/js/node/libs/render/type.js +32 -0
- package/dist/js/node/libs/route/index.js +78 -0
- package/dist/js/node/libs/route/matcher.js +106 -0
- package/dist/js/node/libs/route/route.js +39 -0
- package/dist/js/node/libs/serve-file.js +97 -0
- package/dist/js/node/server/index.js +219 -0
- package/dist/js/node/server/modern-server-split.js +97 -0
- package/dist/js/node/server/modern-server.js +559 -0
- package/dist/js/node/type.js +15 -0
- package/dist/js/node/utils.js +166 -0
- package/dist/js/node/worker-server.js +113 -0
- package/dist/js/treeshaking/constants.js +29 -0
- package/dist/js/treeshaking/index.js +13 -0
- package/dist/js/treeshaking/libs/context/context.js +274 -0
- package/dist/js/treeshaking/libs/context/index.js +5 -0
- package/dist/js/treeshaking/libs/hook-api/index.js +281 -0
- package/dist/js/treeshaking/libs/hook-api/route.js +68 -0
- package/dist/js/treeshaking/libs/hook-api/template.js +127 -0
- package/dist/js/treeshaking/libs/loadConfig.js +82 -0
- package/dist/js/treeshaking/libs/logger.js +205 -0
- package/dist/js/treeshaking/libs/metrics.js +6 -0
- package/dist/js/treeshaking/libs/proxy.js +244 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +291 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +781 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +67 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -0
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +147 -0
- package/dist/js/treeshaking/libs/render/cache/index.js +346 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +154 -0
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +84 -0
- package/dist/js/treeshaking/libs/render/cache/spr.js +492 -0
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
- package/dist/js/treeshaking/libs/render/cache/util.js +280 -0
- package/dist/js/treeshaking/libs/render/index.js +234 -0
- package/dist/js/treeshaking/libs/render/measure.js +146 -0
- package/dist/js/treeshaking/libs/render/reader.js +339 -0
- package/dist/js/treeshaking/libs/render/ssr.js +223 -0
- package/dist/js/treeshaking/libs/render/static.js +216 -0
- package/dist/js/treeshaking/libs/render/type.js +7 -0
- package/dist/js/treeshaking/libs/route/index.js +130 -0
- package/dist/js/treeshaking/libs/route/matcher.js +143 -0
- package/dist/js/treeshaking/libs/route/route.js +40 -0
- package/dist/js/treeshaking/libs/serve-file.js +184 -0
- package/dist/js/treeshaking/server/index.js +505 -0
- package/dist/js/treeshaking/server/modern-server-split.js +360 -0
- package/dist/js/treeshaking/server/modern-server.js +1089 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +147 -0
- package/dist/js/treeshaking/worker-server.js +233 -0
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
};
|
|
61
|
+
};
|
|
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 ");
|
|
66
|
+
};
|
|
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
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
getMiddlewares: getMiddlewares,
|
|
84
|
+
addWebMiddleware: addWebMiddleware,
|
|
85
|
+
addAPIMiddleware: addAPIMiddleware
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var useLocalPrefix = function(url) {
|
|
89
|
+
return isProd() && !url.includes(".");
|
|
90
|
+
};
|
|
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, _output_assetPrefix = output.assetPrefix, assetPrefix = _output_assetPrefix === void 0 ? "/" : _output_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);
|
|
103
|
+
});
|
|
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;
|
|
138
|
+
};
|
|
139
|
+
var isRedirect = function(code) {
|
|
140
|
+
return [
|
|
141
|
+
301,
|
|
142
|
+
302,
|
|
143
|
+
307,
|
|
144
|
+
308
|
|
145
|
+
].includes(code);
|
|
146
|
+
};
|
|
147
|
+
export { createErrorDocument, createMiddlewareCollecter, debug, getStaticReg, headersWithoutCookie, isRedirect, mergeExtension, noop, prepareFavicons, useLocalPrefix };
|
|
@@ -0,0 +1,233 @@
|
|
|
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: []
|
|
39
|
+
};
|
|
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 _ctx_request, _ctx_request1, _ctx_request2;
|
|
126
|
+
import { Logger } from "./libs/logger";
|
|
127
|
+
import { RouteMatchManager } from "./libs/route";
|
|
128
|
+
import { metrics as defaultMetrics } from "./libs/metrics";
|
|
129
|
+
var handleUrl = function(url) {
|
|
130
|
+
return url.replace(/^https?:\/\/.*?\//gi, "/");
|
|
131
|
+
};
|
|
132
|
+
var createHandler = function(manifest) {
|
|
133
|
+
var routeMgr = new RouteMatchManager();
|
|
134
|
+
var pages = manifest.pages, routes = manifest.routes;
|
|
135
|
+
routeMgr.reset(routes);
|
|
136
|
+
return function() {
|
|
137
|
+
var _ref = _asyncToGenerator(function(ctx) {
|
|
138
|
+
var pageMatch, page, _query, _pathname, _params, params, e;
|
|
139
|
+
return __generator(this, function(_state) {
|
|
140
|
+
switch(_state.label){
|
|
141
|
+
case 0:
|
|
142
|
+
pageMatch = routeMgr.match(ctx.url);
|
|
143
|
+
if (!pageMatch) {
|
|
144
|
+
ctx.body = "404: Page not found";
|
|
145
|
+
ctx.status = 404;
|
|
146
|
+
return [
|
|
147
|
+
2
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
page = pages[pageMatch.spec.urlPath];
|
|
151
|
+
(_query = (_ctx_request = ctx.request).query) !== null && _query !== void 0 ? _query : _ctx_request.query = ctx.query;
|
|
152
|
+
(_pathname = (_ctx_request1 = ctx.request).pathname) !== null && _pathname !== void 0 ? _pathname : _ctx_request1.pathname = ctx.pathname;
|
|
153
|
+
(_params = (_ctx_request2 = ctx.request).params) !== null && _params !== void 0 ? _params : _ctx_request2.params = ctx.params;
|
|
154
|
+
params = pageMatch.parseURLParams(ctx.url);
|
|
155
|
+
if (!page.serverRender) return [
|
|
156
|
+
3,
|
|
157
|
+
4
|
|
158
|
+
];
|
|
159
|
+
_state.label = 1;
|
|
160
|
+
case 1:
|
|
161
|
+
_state.trys.push([
|
|
162
|
+
1,
|
|
163
|
+
3,
|
|
164
|
+
,
|
|
165
|
+
4
|
|
166
|
+
]);
|
|
167
|
+
return [
|
|
168
|
+
4,
|
|
169
|
+
page.serverRender({
|
|
170
|
+
entryName: page.entryName,
|
|
171
|
+
template: page.template,
|
|
172
|
+
query: ctx.query,
|
|
173
|
+
request: ctx.request,
|
|
174
|
+
response: ctx.response,
|
|
175
|
+
pathname: ctx.pathname,
|
|
176
|
+
req: ctx.request,
|
|
177
|
+
res: ctx.response,
|
|
178
|
+
params: ctx.params || params || {},
|
|
179
|
+
logger: ctx.logger || new Logger({
|
|
180
|
+
level: "warn"
|
|
181
|
+
}),
|
|
182
|
+
metrics: ctx.metrics || defaultMetrics,
|
|
183
|
+
loadableStats: ctx.loadableStats,
|
|
184
|
+
routeManifest: ctx.routeManifest
|
|
185
|
+
})
|
|
186
|
+
];
|
|
187
|
+
case 2:
|
|
188
|
+
ctx.body = _state.sent();
|
|
189
|
+
ctx.status = 200;
|
|
190
|
+
return [
|
|
191
|
+
2
|
|
192
|
+
];
|
|
193
|
+
case 3:
|
|
194
|
+
e = _state.sent();
|
|
195
|
+
if (page.template) {
|
|
196
|
+
ctx.body = page.template;
|
|
197
|
+
ctx.status = 200;
|
|
198
|
+
return [
|
|
199
|
+
2
|
|
200
|
+
];
|
|
201
|
+
} else {
|
|
202
|
+
ctx.body = "404: not found";
|
|
203
|
+
ctx.status = 404;
|
|
204
|
+
return [
|
|
205
|
+
2
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
return [
|
|
209
|
+
3,
|
|
210
|
+
4
|
|
211
|
+
];
|
|
212
|
+
case 4:
|
|
213
|
+
if (page.template) {
|
|
214
|
+
ctx.body = page.template;
|
|
215
|
+
ctx.status = 200;
|
|
216
|
+
return [
|
|
217
|
+
2
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
ctx.body = "404: not found";
|
|
221
|
+
ctx.status = 404;
|
|
222
|
+
return [
|
|
223
|
+
2
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return function(ctx) {
|
|
229
|
+
return _ref.apply(this, arguments);
|
|
230
|
+
};
|
|
231
|
+
}();
|
|
232
|
+
};
|
|
233
|
+
export { createHandler, handleUrl };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node/http" />
|
|
5
|
-
/// <reference types=".dts-temp/
|
|
5
|
+
/// <reference types=".dts-temp/gxxotyts4i9oiicydl5gf/src/type" />
|
|
6
6
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
7
7
|
import qs from 'querystring';
|
|
8
8
|
import type { ModernServerContext as ModernServerContextInterface } from '@modern-js/types';
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node/http" />
|
|
3
|
-
/// <reference types=".dts-temp/
|
|
3
|
+
/// <reference types=".dts-temp/gxxotyts4i9oiicydl5gf/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.9.0",
|
|
14
|
+
"version": "2.9.1-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/cookie": "^0.4.1",
|
|
62
|
-
"@types/jest": "^
|
|
62
|
+
"@types/jest": "^29",
|
|
63
63
|
"@types/lru-cache": "^5.1.1",
|
|
64
64
|
"@types/merge-deep": "^3.0.0",
|
|
65
65
|
"@types/node": "^14",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@types/fresh": "^0.5.0",
|
|
68
68
|
"@types/serve-static": "^1.13.10",
|
|
69
69
|
"axios": "^1.2.1",
|
|
70
|
-
"jest": "^
|
|
70
|
+
"jest": "^29",
|
|
71
71
|
"node-mocks-http": "^1.11.0",
|
|
72
72
|
"portfinder": "^1.0.28",
|
|
73
73
|
"typescript": "^4",
|