@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,157 +1,281 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_defineProperty(this, "cookies", void 0);
|
|
13
|
-
_defineProperty(this, "res", void 0);
|
|
14
|
-
_defineProperty(this, "_cookie", void 0);
|
|
15
|
-
this.res = res;
|
|
16
|
-
this._cookie = cookie.parse(res.getHeader('set-cookie') || '');
|
|
17
|
-
this.cookies = {
|
|
18
|
-
get: this.getCookie.bind(this),
|
|
19
|
-
set: this.setCookie.bind(this),
|
|
20
|
-
"delete": this.deleteCookie.bind(this),
|
|
21
|
-
clear: this.clearCookie.bind(this),
|
|
22
|
-
apply: this.applyCookie.bind(this)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
_createClass(Response, [{
|
|
26
|
-
key: "get",
|
|
27
|
-
value: function get(key) {
|
|
28
|
-
return this.res.getHeader(key);
|
|
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 _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _classCallCheck(instance, Constructor) {
|
|
10
|
+
if (!(instance instanceof Constructor)) {
|
|
11
|
+
throw new TypeError("Cannot call a class as a function");
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
}
|
|
14
|
+
function _defineProperties(target, props) {
|
|
15
|
+
for(var i = 0; i < props.length; i++){
|
|
16
|
+
var descriptor = props[i];
|
|
17
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
18
|
+
descriptor.configurable = true;
|
|
19
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
20
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
34
21
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
}
|
|
23
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
24
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
25
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
26
|
+
return Constructor;
|
|
27
|
+
}
|
|
28
|
+
function _defineProperty(obj, key, value) {
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
obj[key] = value;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
function _iterableToArrayLimit(arr, i) {
|
|
42
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
43
|
+
if (_i == null) return;
|
|
44
|
+
var _arr = [];
|
|
45
|
+
var _n = true;
|
|
46
|
+
var _d = false;
|
|
47
|
+
var _s, _e;
|
|
48
|
+
try {
|
|
49
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
50
|
+
_arr.push(_s.value);
|
|
51
|
+
if (i && _arr.length === i) break;
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_d = true;
|
|
55
|
+
_e = err;
|
|
56
|
+
} finally{
|
|
57
|
+
try {
|
|
58
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
59
|
+
} finally{
|
|
60
|
+
if (_d) throw _e;
|
|
61
|
+
}
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
return _arr;
|
|
64
|
+
}
|
|
65
|
+
function _nonIterableRest() {
|
|
66
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
67
|
+
}
|
|
68
|
+
function _objectSpread(target) {
|
|
69
|
+
for(var i = 1; i < arguments.length; i++){
|
|
70
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
71
|
+
var ownKeys = Object.keys(source);
|
|
72
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
73
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
74
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
ownKeys.forEach(function(key) {
|
|
78
|
+
_defineProperty(target, key, source[key]);
|
|
79
|
+
});
|
|
49
80
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
83
|
+
function ownKeys(object, enumerableOnly) {
|
|
84
|
+
var keys = Object.keys(object);
|
|
85
|
+
if (Object.getOwnPropertySymbols) {
|
|
86
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
87
|
+
if (enumerableOnly) {
|
|
88
|
+
symbols = symbols.filter(function(sym) {
|
|
89
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
keys.push.apply(keys, symbols);
|
|
56
93
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
94
|
+
return keys;
|
|
95
|
+
}
|
|
96
|
+
function _objectSpreadProps(target, source) {
|
|
97
|
+
source = source != null ? source : {};
|
|
98
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
99
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
100
|
+
} else {
|
|
101
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
102
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
103
|
+
});
|
|
61
104
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
function _slicedToArray(arr, i) {
|
|
108
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
109
|
+
}
|
|
110
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
111
|
+
if (!o) return;
|
|
112
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
113
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
114
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
115
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
116
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
117
|
+
}
|
|
118
|
+
import cookie from "cookie";
|
|
119
|
+
import { RouteAPI } from "./route";
|
|
120
|
+
import { TemplateAPI } from "./template";
|
|
121
|
+
var Response = /*#__PURE__*/ function() {
|
|
122
|
+
"use strict";
|
|
123
|
+
function Response(res) {
|
|
124
|
+
_classCallCheck(this, Response);
|
|
125
|
+
_defineProperty(this, "cookies", void 0);
|
|
126
|
+
_defineProperty(this, "res", void 0);
|
|
127
|
+
_defineProperty(this, "_cookie", void 0);
|
|
128
|
+
this.res = res;
|
|
129
|
+
this._cookie = cookie.parse(res.getHeader("set-cookie") || "");
|
|
130
|
+
this.cookies = {
|
|
131
|
+
get: this.getCookie.bind(this),
|
|
132
|
+
set: this.setCookie.bind(this),
|
|
133
|
+
delete: this.deleteCookie.bind(this),
|
|
134
|
+
clear: this.clearCookie.bind(this),
|
|
135
|
+
apply: this.applyCookie.bind(this)
|
|
136
|
+
};
|
|
93
137
|
}
|
|
94
|
-
|
|
95
|
-
|
|
138
|
+
_createClass(Response, [
|
|
139
|
+
{
|
|
140
|
+
key: "get",
|
|
141
|
+
value: function get(key) {
|
|
142
|
+
return this.res.getHeader(key);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
key: "set",
|
|
147
|
+
value: function set(key, value) {
|
|
148
|
+
return this.res.setHeader(key, value);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
key: "status",
|
|
153
|
+
value: function status(code) {
|
|
154
|
+
this.res.statusCode = code;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
key: "getCookie",
|
|
159
|
+
value: function getCookie(key) {
|
|
160
|
+
return this._cookie[key];
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
key: "setCookie",
|
|
165
|
+
value: function setCookie(key, value) {
|
|
166
|
+
this._cookie[key] = value;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: "deleteCookie",
|
|
171
|
+
value: function deleteCookie(key) {
|
|
172
|
+
if (this._cookie[key]) {
|
|
173
|
+
delete this._cookie[key];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
key: "clearCookie",
|
|
179
|
+
value: function clearCookie() {
|
|
180
|
+
this._cookie = {};
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "applyCookie",
|
|
185
|
+
value: function applyCookie() {
|
|
186
|
+
var str = Object.entries(this._cookie).map(function(param) {
|
|
187
|
+
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
188
|
+
return cookie.serialize(key, value);
|
|
189
|
+
}).join("; ");
|
|
190
|
+
if (str) {
|
|
191
|
+
this.res.setHeader("set-cookie", str);
|
|
192
|
+
} else {
|
|
193
|
+
this.res.removeHeader("set-cookie");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "raw",
|
|
199
|
+
value: function raw(body, options) {
|
|
200
|
+
var _this = this;
|
|
201
|
+
var ref = options || {}, status = ref.status, _headers = ref.headers, headers = _headers === void 0 ? {} : _headers;
|
|
202
|
+
Object.entries(headers).forEach(function(param) {
|
|
203
|
+
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
204
|
+
_this.res.setHeader(key, value);
|
|
205
|
+
});
|
|
206
|
+
if (status) {
|
|
207
|
+
this.res.statusCode = status;
|
|
208
|
+
}
|
|
209
|
+
this.res.end(body);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
return Response;
|
|
96
214
|
}();
|
|
97
|
-
var Request = /*#__PURE__*/function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
value: function getCookie(key) {
|
|
120
|
-
return this._cookie[key];
|
|
215
|
+
var Request = /*#__PURE__*/ function() {
|
|
216
|
+
"use strict";
|
|
217
|
+
function Request(ctx) {
|
|
218
|
+
_classCallCheck(this, Request);
|
|
219
|
+
_defineProperty(this, "url", void 0);
|
|
220
|
+
_defineProperty(this, "host", void 0);
|
|
221
|
+
_defineProperty(this, "pathname", void 0);
|
|
222
|
+
_defineProperty(this, "query", void 0);
|
|
223
|
+
_defineProperty(this, "headers", void 0);
|
|
224
|
+
_defineProperty(this, "cookie", void 0);
|
|
225
|
+
_defineProperty(this, "cookies", void 0);
|
|
226
|
+
_defineProperty(this, "_cookie", void 0);
|
|
227
|
+
this.url = ctx.url;
|
|
228
|
+
this.host = ctx.host;
|
|
229
|
+
this.pathname = ctx.path;
|
|
230
|
+
this.query = ctx.query;
|
|
231
|
+
this.headers = ctx.headers;
|
|
232
|
+
this.cookie = ctx.headers.cookie || "";
|
|
233
|
+
this._cookie = cookie.parse(this.cookie);
|
|
234
|
+
this.cookies = {
|
|
235
|
+
get: this.getCookie.bind(this)
|
|
236
|
+
};
|
|
121
237
|
}
|
|
122
|
-
|
|
123
|
-
|
|
238
|
+
_createClass(Request, [
|
|
239
|
+
{
|
|
240
|
+
key: "getCookie",
|
|
241
|
+
value: function getCookie(key) {
|
|
242
|
+
return this._cookie[key];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
]);
|
|
246
|
+
return Request;
|
|
124
247
|
}();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
248
|
+
var base = function(context) {
|
|
249
|
+
var res = context.res;
|
|
250
|
+
return {
|
|
251
|
+
response: new Response(res),
|
|
252
|
+
request: new Request(context),
|
|
253
|
+
logger: context.logger,
|
|
254
|
+
metrics: context.metrics
|
|
255
|
+
};
|
|
133
256
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
257
|
+
var createAfterMatchContext = function(context, entryName) {
|
|
258
|
+
var baseContext = base(context);
|
|
259
|
+
return _objectSpreadProps(_objectSpread({}, baseContext), {
|
|
260
|
+
router: new RouteAPI(entryName)
|
|
261
|
+
});
|
|
139
262
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
263
|
+
var createAfterRenderContext = function(context, content) {
|
|
264
|
+
var baseContext = base(context);
|
|
265
|
+
return _objectSpreadProps(_objectSpread({}, baseContext), {
|
|
266
|
+
template: new TemplateAPI(content)
|
|
267
|
+
});
|
|
145
268
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
};
|
|
269
|
+
var createMiddlewareContext = function(context) {
|
|
270
|
+
var baseContext = base(context);
|
|
271
|
+
return _objectSpreadProps(_objectSpread({}, baseContext), {
|
|
272
|
+
response: _objectSpreadProps(_objectSpread({}, baseContext.response), {
|
|
273
|
+
locals: context.res.locals || {}
|
|
274
|
+
}),
|
|
275
|
+
source: {
|
|
276
|
+
req: context.req,
|
|
277
|
+
res: context.res
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
export { base, createAfterMatchContext, createAfterRenderContext, createMiddlewareContext };
|
|
@@ -1,33 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export var RouteAPI = /*#__PURE__*/function () {
|
|
5
|
-
function RouteAPI(entryName) {
|
|
6
|
-
_classCallCheck(this, RouteAPI);
|
|
7
|
-
_defineProperty(this, "current", void 0);
|
|
8
|
-
_defineProperty(this, "status", void 0);
|
|
9
|
-
_defineProperty(this, "url", void 0);
|
|
10
|
-
this.current = entryName;
|
|
11
|
-
this.status = 200;
|
|
12
|
-
this.url = '';
|
|
13
|
-
}
|
|
14
|
-
_createClass(RouteAPI, [{
|
|
15
|
-
key: "redirect",
|
|
16
|
-
value: function redirect(url) {
|
|
17
|
-
var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 302;
|
|
18
|
-
this.url = url;
|
|
19
|
-
this.status = status;
|
|
1
|
+
function _classCallCheck(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
20
4
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
}
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _defineProperty(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
var RouteAPI = /*#__PURE__*/ function() {
|
|
34
|
+
"use strict";
|
|
35
|
+
function RouteAPI(entryName) {
|
|
36
|
+
_classCallCheck(this, RouteAPI);
|
|
37
|
+
_defineProperty(this, "current", void 0);
|
|
38
|
+
_defineProperty(this, "status", void 0);
|
|
39
|
+
_defineProperty(this, "url", void 0);
|
|
40
|
+
this.current = entryName;
|
|
41
|
+
this.status = 200;
|
|
42
|
+
this.url = "";
|
|
43
|
+
}
|
|
44
|
+
_createClass(RouteAPI, [
|
|
45
|
+
{
|
|
46
|
+
key: "redirect",
|
|
47
|
+
value: function redirect(url) {
|
|
48
|
+
var status = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 302;
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.status = status;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: "rewrite",
|
|
55
|
+
value: function rewrite(entryName) {
|
|
56
|
+
this.current = entryName;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "use",
|
|
61
|
+
value: function use(entryName) {
|
|
62
|
+
this.rewrite(entryName);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
66
|
+
return RouteAPI;
|
|
67
|
+
}();
|
|
68
|
+
export { RouteAPI };
|