@modern-js/server-core 2.54.6 → 2.56.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/adapters/node/plugins/resource.js +1 -1
- package/dist/cjs/constants.js +12 -9
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/customServer/index.js +5 -5
- package/dist/cjs/plugins/index.js +7 -3
- package/dist/cjs/plugins/log.js +3 -3
- package/dist/cjs/plugins/monitors.js +183 -0
- package/dist/cjs/plugins/render/dataHandler.js +3 -2
- package/dist/cjs/plugins/render/index.js +6 -4
- package/dist/cjs/plugins/render/render.js +32 -15
- package/dist/cjs/plugins/render/ssrCache.js +72 -83
- package/dist/cjs/plugins/render/ssrRender.js +40 -145
- package/dist/cjs/types/requestHandler.js +16 -0
- package/dist/cjs/utils/error.js +3 -3
- package/dist/cjs/utils/transformStream.js +1 -1
- package/dist/esm/adapters/node/plugins/resource.js +1 -1
- package/dist/esm/constants.js +10 -8
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugins/customServer/index.js +8 -8
- package/dist/esm/plugins/index.js +4 -2
- package/dist/esm/plugins/log.js +4 -4
- package/dist/esm/plugins/monitors.js +261 -0
- package/dist/esm/plugins/render/dataHandler.js +4 -3
- package/dist/esm/plugins/render/index.js +6 -4
- package/dist/esm/plugins/render/render.js +51 -24
- package/dist/esm/plugins/render/ssrCache.js +101 -131
- package/dist/esm/plugins/render/ssrRender.js +55 -175
- package/dist/esm/types/requestHandler.js +0 -0
- package/dist/esm/utils/error.js +3 -3
- package/dist/esm/utils/transformStream.js +16 -2
- package/dist/esm-node/adapters/node/plugins/resource.js +1 -1
- package/dist/esm-node/constants.js +10 -8
- package/dist/esm-node/index.js +1 -0
- package/dist/esm-node/plugins/customServer/index.js +6 -6
- package/dist/esm-node/plugins/index.js +4 -2
- package/dist/esm-node/plugins/log.js +3 -3
- package/dist/esm-node/plugins/monitors.js +156 -0
- package/dist/esm-node/plugins/render/dataHandler.js +3 -2
- package/dist/esm-node/plugins/render/index.js +5 -3
- package/dist/esm-node/plugins/render/render.js +33 -16
- package/dist/esm-node/plugins/render/ssrCache.js +73 -74
- package/dist/esm-node/plugins/render/ssrRender.js +43 -137
- package/dist/esm-node/types/requestHandler.js +0 -0
- package/dist/esm-node/utils/error.js +3 -3
- package/dist/esm-node/utils/transformStream.js +1 -1
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/monitors.d.ts +6 -0
- package/dist/types/plugins/render/dataHandler.d.ts +1 -1
- package/dist/types/plugins/render/render.d.ts +3 -2
- package/dist/types/plugins/render/ssrCache.d.ts +7 -11
- package/dist/types/plugins/render/ssrRender.d.ts +10 -10
- package/dist/types/types/config/html.d.ts +11 -0
- package/dist/types/types/config/output.d.ts +8 -0
- package/dist/types/types/render.d.ts +7 -4
- package/dist/types/types/requestHandler.d.ts +41 -0
- package/dist/types/types/server.d.ts +13 -4
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/transformStream.d.ts +1 -1
- package/package.json +7 -8
- package/dist/cjs/plugins/monitor.js +0 -87
- package/dist/cjs/plugins/render/serverTiming.js +0 -40
- package/dist/esm/plugins/monitor.js +0 -120
- package/dist/esm/plugins/render/serverTiming.js +0 -21
- package/dist/esm-node/plugins/monitor.js +0 -62
- package/dist/esm-node/plugins/render/serverTiming.js +0 -16
- package/dist/types/plugins/monitor.d.ts +0 -9
- package/dist/types/plugins/render/serverTiming.d.ts +0 -7
|
@@ -1,139 +1,66 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as
|
|
2
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import { createMemoryStorage } from "@modern-js/runtime-utils/storer";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { X_RENDER_CACHE } from "../../constants";
|
|
7
|
+
import { createTransformStream, getPathname } from "../../utils";
|
|
8
|
+
function processCache(_) {
|
|
8
9
|
return _processCache.apply(this, arguments);
|
|
9
10
|
}
|
|
10
11
|
function _processCache() {
|
|
11
|
-
_processCache = _async_to_generator(function(
|
|
12
|
-
var
|
|
12
|
+
_processCache = _async_to_generator(function(param) {
|
|
13
|
+
var request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus, response, decoder, stream, reader, writer, html, push;
|
|
13
14
|
return _ts_generator(this, function(_state) {
|
|
14
15
|
switch (_state.label) {
|
|
15
16
|
case 0:
|
|
17
|
+
request = param.request, key = param.key, requestHandler = param.requestHandler, requestHandlerOptions = param.requestHandlerOptions, ttl = param.ttl, container = param.container, cacheStatus = param.cacheStatus;
|
|
16
18
|
return [
|
|
17
19
|
4,
|
|
18
|
-
|
|
20
|
+
requestHandler(request, requestHandlerOptions)
|
|
19
21
|
];
|
|
20
22
|
case 1:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
_state.sent();
|
|
52
|
-
return [
|
|
53
|
-
2,
|
|
54
|
-
{
|
|
55
|
-
data: renderResult,
|
|
56
|
-
status
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
case 4:
|
|
60
|
-
return [
|
|
61
|
-
4,
|
|
62
|
-
import("stream").catch(function(_) {
|
|
63
|
-
return {
|
|
64
|
-
Readable: void 0
|
|
65
|
-
};
|
|
66
|
-
})
|
|
67
|
-
];
|
|
68
|
-
case 5:
|
|
69
|
-
Readable = _state.sent().Readable;
|
|
70
|
-
runtimeEnv = getRuntimeEnv();
|
|
71
|
-
streamModule = "../../adapters/node/polyfills/stream";
|
|
72
|
-
if (!(runtimeEnv === "node"))
|
|
23
|
+
response = _state.sent();
|
|
24
|
+
decoder = new TextDecoder();
|
|
25
|
+
if (response.body) {
|
|
26
|
+
stream = createTransformStream();
|
|
27
|
+
reader = response.body.getReader();
|
|
28
|
+
writer = stream.writable.getWriter();
|
|
29
|
+
html = "";
|
|
30
|
+
push = function() {
|
|
31
|
+
return reader.read().then(function(param2) {
|
|
32
|
+
var done = param2.done, value = param2.value;
|
|
33
|
+
if (done) {
|
|
34
|
+
var current = Date.now();
|
|
35
|
+
var cache = {
|
|
36
|
+
val: html,
|
|
37
|
+
cursor: current
|
|
38
|
+
};
|
|
39
|
+
container.set(key, JSON.stringify(cache), {
|
|
40
|
+
ttl
|
|
41
|
+
});
|
|
42
|
+
writer.close();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var content = decoder.decode(value);
|
|
46
|
+
html += content;
|
|
47
|
+
writer.write(value);
|
|
48
|
+
push();
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
push();
|
|
52
|
+
cacheStatus && response.headers.set(X_RENDER_CACHE, cacheStatus);
|
|
73
53
|
return [
|
|
74
|
-
|
|
75
|
-
|
|
54
|
+
2,
|
|
55
|
+
new Response(stream.readable, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
headers: response.headers
|
|
58
|
+
})
|
|
76
59
|
];
|
|
77
|
-
|
|
78
|
-
4,
|
|
79
|
-
import(streamModule).catch(function(_) {
|
|
80
|
-
return {
|
|
81
|
-
createReadableStreamFromReadable: void 0
|
|
82
|
-
};
|
|
83
|
-
})
|
|
84
|
-
];
|
|
85
|
-
case 6:
|
|
86
|
-
_tmp = _state.sent();
|
|
87
|
-
return [
|
|
88
|
-
3,
|
|
89
|
-
8
|
|
90
|
-
];
|
|
91
|
-
case 7:
|
|
92
|
-
_tmp = {
|
|
93
|
-
createReadableStreamFromReadable: void 0
|
|
94
|
-
};
|
|
95
|
-
_state.label = 8;
|
|
96
|
-
case 8:
|
|
97
|
-
createReadableStreamFromReadable = _tmp.createReadableStreamFromReadable;
|
|
98
|
-
body = // TODO: remove node:stream, move it to ssr entry.
|
|
99
|
-
Readable && _instanceof(renderResult, Readable) ? createReadableStreamFromReadable === null || createReadableStreamFromReadable === void 0 ? void 0 : createReadableStreamFromReadable(renderResult) : renderResult;
|
|
100
|
-
html = "";
|
|
101
|
-
stream = createTransformStream(function(chunk) {
|
|
102
|
-
html += chunk;
|
|
103
|
-
return chunk;
|
|
104
|
-
});
|
|
105
|
-
reader = body.getReader();
|
|
106
|
-
writer = stream.writable.getWriter();
|
|
107
|
-
push = function() {
|
|
108
|
-
reader.read().then(function(param) {
|
|
109
|
-
var done = param.done, value = param.value;
|
|
110
|
-
if (done) {
|
|
111
|
-
var current2 = Date.now();
|
|
112
|
-
var cache2 = {
|
|
113
|
-
val: html,
|
|
114
|
-
cursor: current2
|
|
115
|
-
};
|
|
116
|
-
container.set(key, JSON.stringify(cache2), {
|
|
117
|
-
ttl
|
|
118
|
-
});
|
|
119
|
-
writer.close();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
writer.write(value);
|
|
123
|
-
push();
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
push();
|
|
60
|
+
}
|
|
127
61
|
return [
|
|
128
62
|
2,
|
|
129
|
-
|
|
130
|
-
data: stream.readable,
|
|
131
|
-
status
|
|
132
|
-
}
|
|
133
|
-
];
|
|
134
|
-
case 9:
|
|
135
|
-
return [
|
|
136
|
-
2
|
|
63
|
+
response
|
|
137
64
|
];
|
|
138
65
|
}
|
|
139
66
|
});
|
|
@@ -206,11 +133,11 @@ function getCacheResult(request, options) {
|
|
|
206
133
|
}
|
|
207
134
|
function _getCacheResult() {
|
|
208
135
|
_getCacheResult = _async_to_generator(function(request, options) {
|
|
209
|
-
var cacheControl,
|
|
136
|
+
var cacheControl, _options_container, container, requestHandler, requestHandlerOptions, key, value, maxAge, staleWhileRevalidate, ttl, cache, interval, cacheStatus, cacheStatus1;
|
|
210
137
|
return _ts_generator(this, function(_state) {
|
|
211
138
|
switch (_state.label) {
|
|
212
139
|
case 0:
|
|
213
|
-
cacheControl = options.cacheControl,
|
|
140
|
+
cacheControl = options.cacheControl, _options_container = options.container, container = _options_container === void 0 ? storage : _options_container, requestHandler = options.requestHandler, requestHandlerOptions = options.requestHandlerOptions;
|
|
214
141
|
key = computedKey(request, cacheControl);
|
|
215
142
|
return [
|
|
216
143
|
4,
|
|
@@ -224,32 +151,75 @@ function _getCacheResult() {
|
|
|
224
151
|
cache = JSON.parse(value);
|
|
225
152
|
interval = Date.now() - cache.cursor;
|
|
226
153
|
if (interval <= maxAge) {
|
|
154
|
+
cacheStatus = "hit";
|
|
227
155
|
return [
|
|
228
156
|
2,
|
|
229
|
-
{
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
157
|
+
new Response(cache.val, {
|
|
158
|
+
headers: _define_property({}, X_RENDER_CACHE, cacheStatus)
|
|
159
|
+
})
|
|
233
160
|
];
|
|
234
161
|
} else if (interval <= staleWhileRevalidate + maxAge) {
|
|
235
|
-
processCache(
|
|
162
|
+
processCache({
|
|
163
|
+
key,
|
|
164
|
+
request,
|
|
165
|
+
requestHandler,
|
|
166
|
+
requestHandlerOptions,
|
|
167
|
+
ttl,
|
|
168
|
+
container
|
|
169
|
+
}).then(function() {
|
|
170
|
+
var _ref = _async_to_generator(function(response) {
|
|
171
|
+
return _ts_generator(this, function(_state2) {
|
|
172
|
+
switch (_state2.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
return [
|
|
175
|
+
4,
|
|
176
|
+
response.text()
|
|
177
|
+
];
|
|
178
|
+
case 1:
|
|
179
|
+
_state2.sent();
|
|
180
|
+
return [
|
|
181
|
+
2
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
return function(response) {
|
|
187
|
+
return _ref.apply(this, arguments);
|
|
188
|
+
};
|
|
189
|
+
}());
|
|
190
|
+
cacheStatus1 = "stale";
|
|
236
191
|
return [
|
|
237
192
|
2,
|
|
238
|
-
{
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
193
|
+
new Response(cache.val, {
|
|
194
|
+
headers: _define_property({}, X_RENDER_CACHE, cacheStatus1)
|
|
195
|
+
})
|
|
242
196
|
];
|
|
243
197
|
} else {
|
|
244
198
|
return [
|
|
245
199
|
2,
|
|
246
|
-
processCache(
|
|
200
|
+
processCache({
|
|
201
|
+
key,
|
|
202
|
+
request,
|
|
203
|
+
requestHandler,
|
|
204
|
+
requestHandlerOptions,
|
|
205
|
+
ttl,
|
|
206
|
+
container,
|
|
207
|
+
cacheStatus: "expired"
|
|
208
|
+
})
|
|
247
209
|
];
|
|
248
210
|
}
|
|
249
211
|
} else {
|
|
250
212
|
return [
|
|
251
213
|
2,
|
|
252
|
-
processCache(
|
|
214
|
+
processCache({
|
|
215
|
+
key,
|
|
216
|
+
request,
|
|
217
|
+
requestHandler,
|
|
218
|
+
requestHandlerOptions,
|
|
219
|
+
ttl,
|
|
220
|
+
container,
|
|
221
|
+
cacheStatus: "miss"
|
|
222
|
+
})
|
|
253
223
|
];
|
|
254
224
|
}
|
|
255
225
|
return [
|
|
@@ -1,42 +1,24 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
|
-
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
4
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { X_MODERNJS_RENDER, X_RENDER_CACHE } from "../../constants";
|
|
9
|
-
import { ServerTiming } from "./serverTiming";
|
|
4
|
+
import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
|
|
5
|
+
import { parseHeaders, getPathname } from "../../utils";
|
|
6
|
+
import { X_MODERNJS_RENDER } from "../../constants";
|
|
10
7
|
import { matchCacheControl, getCacheResult } from "./ssrCache";
|
|
11
|
-
var
|
|
12
|
-
init: function init() {
|
|
13
|
-
},
|
|
14
|
-
reportError: function reportError() {
|
|
15
|
-
},
|
|
16
|
-
reportTiming: function reportTiming() {
|
|
17
|
-
},
|
|
18
|
-
reportInfo: function reportInfo() {
|
|
19
|
-
},
|
|
20
|
-
reportWarn: function reportWarn() {
|
|
21
|
-
}
|
|
22
|
-
};
|
|
8
|
+
var SERVER_RUNTIME_ENTRY = "requestHandler";
|
|
23
9
|
function ssrRender(request, _) {
|
|
24
10
|
return _ssrRender.apply(this, arguments);
|
|
25
11
|
}
|
|
26
12
|
function _ssrRender() {
|
|
27
13
|
_ssrRender = _async_to_generator(function(request, param) {
|
|
28
|
-
var routeInfo, html,
|
|
14
|
+
var routeInfo, html, userConfig, staticGenerate, nodeReq, serverManifest, locals, params, loaderContext, reporter, cacheConfig, logger, metrics, onError, onTiming, _serverManifest_renderBundles, entryName, loadableStats, routeManifest, headers, key, renderBundle, requestHandler, config, requestHandlerOptions, cacheControl, response;
|
|
29
15
|
return _ts_generator(this, function(_state) {
|
|
30
16
|
switch (_state.label) {
|
|
31
17
|
case 0:
|
|
32
|
-
routeInfo = param.routeInfo, html = param.html, staticGenerate = param.staticGenerate,
|
|
18
|
+
routeInfo = param.routeInfo, html = param.html, userConfig = param.config, staticGenerate = param.staticGenerate, nodeReq = param.nodeReq, serverManifest = param.serverManifest, locals = param.locals, params = param.params, loaderContext = param.loaderContext, reporter = param.reporter, cacheConfig = param.cacheConfig, logger = param.logger, metrics = param.metrics, onError = param.onError, onTiming = param.onTiming;
|
|
33
19
|
entryName = routeInfo.entryName;
|
|
34
20
|
loadableStats = serverManifest.loadableStats || {};
|
|
35
21
|
routeManifest = serverManifest.routeManifest || {};
|
|
36
|
-
host = getHost(request);
|
|
37
|
-
isSpider = isbot.default(request.headers.get("user-agent"));
|
|
38
|
-
responseProxy = new ResponseProxy();
|
|
39
|
-
query = parseQuery(request);
|
|
40
22
|
headers = parseHeaders(request);
|
|
41
23
|
if (nodeReq) {
|
|
42
24
|
for (var key2 in nodeReq.headers) {
|
|
@@ -45,164 +27,82 @@ function _ssrRender() {
|
|
|
45
27
|
}
|
|
46
28
|
}
|
|
47
29
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
30
|
+
renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
|
|
31
|
+
if (!renderBundle) {
|
|
32
|
+
throw new Error("Can't found renderBundle ".concat(entryName || MAIN_ENTRY_NAME));
|
|
33
|
+
}
|
|
34
|
+
return [
|
|
35
|
+
4,
|
|
36
|
+
renderBundle[SERVER_RUNTIME_ENTRY]
|
|
37
|
+
];
|
|
38
|
+
case 1:
|
|
39
|
+
requestHandler = _state.sent();
|
|
40
|
+
config = createRequestHandlerConfig(userConfig);
|
|
41
|
+
requestHandlerOptions = {
|
|
42
|
+
resource: {
|
|
43
|
+
route: routeInfo,
|
|
44
|
+
loadableStats,
|
|
45
|
+
routeManifest,
|
|
46
|
+
htmlTemplate: html,
|
|
47
|
+
entryName: entryName || MAIN_ENTRY_NAME
|
|
66
48
|
},
|
|
67
|
-
|
|
68
|
-
template: html,
|
|
69
|
-
loadableStats,
|
|
49
|
+
params,
|
|
70
50
|
loaderContext,
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
config,
|
|
52
|
+
locals,
|
|
53
|
+
reporter,
|
|
73
54
|
staticGenerate,
|
|
74
55
|
logger,
|
|
75
56
|
metrics,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/** @deprecated node req */
|
|
79
|
-
req: nodeReq || request,
|
|
80
|
-
/** @deprecated node res */
|
|
81
|
-
res: void 0,
|
|
82
|
-
isSpider,
|
|
83
|
-
nonce
|
|
57
|
+
onError,
|
|
58
|
+
onTiming
|
|
84
59
|
};
|
|
85
|
-
renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
|
|
86
|
-
if (!renderBundle) {
|
|
87
|
-
throw new Error("Can't found renderBundle ".concat(entryName || MAIN_ENTRY_NAME));
|
|
88
|
-
}
|
|
89
|
-
runtimeEnv = getRuntimeEnv();
|
|
90
|
-
render = renderBundle[SERVER_RENDER_FUNCTION_NAME];
|
|
91
60
|
return [
|
|
92
61
|
4,
|
|
93
62
|
matchCacheControl(cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.strategy, nodeReq || new IncomingMessgeProxy(request))
|
|
94
63
|
];
|
|
95
|
-
case
|
|
64
|
+
case 2:
|
|
96
65
|
cacheControl = _state.sent();
|
|
97
66
|
if (!cacheControl)
|
|
98
67
|
return [
|
|
99
68
|
3,
|
|
100
|
-
|
|
69
|
+
4
|
|
101
70
|
];
|
|
102
71
|
return [
|
|
103
72
|
4,
|
|
104
73
|
getCacheResult(request, {
|
|
105
74
|
cacheControl,
|
|
106
75
|
container: cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.container,
|
|
107
|
-
|
|
108
|
-
|
|
76
|
+
requestHandler,
|
|
77
|
+
requestHandlerOptions
|
|
109
78
|
})
|
|
110
79
|
];
|
|
111
|
-
case 2:
|
|
112
|
-
_ref = _state.sent(), data = _ref.data, status = _ref.status;
|
|
113
|
-
ssrResult = data;
|
|
114
|
-
cacheStatus = status;
|
|
115
|
-
return [
|
|
116
|
-
3,
|
|
117
|
-
5
|
|
118
|
-
];
|
|
119
80
|
case 3:
|
|
81
|
+
response = _state.sent();
|
|
120
82
|
return [
|
|
121
|
-
|
|
122
|
-
|
|
83
|
+
3,
|
|
84
|
+
6
|
|
123
85
|
];
|
|
124
86
|
case 4:
|
|
125
|
-
ssrResult = _state.sent();
|
|
126
|
-
_state.label = 5;
|
|
127
|
-
case 5:
|
|
128
|
-
redirection = ssrContext.redirection;
|
|
129
|
-
if (cacheStatus) {
|
|
130
|
-
responseProxy.headers.set(X_RENDER_CACHE, cacheStatus);
|
|
131
|
-
}
|
|
132
|
-
responseProxy.headers.set(X_MODERNJS_RENDER, "server");
|
|
133
|
-
if (redirection.url) {
|
|
134
|
-
headers1 = responseProxy.headers;
|
|
135
|
-
headers1.set("Location", redirection.url);
|
|
136
|
-
return [
|
|
137
|
-
2,
|
|
138
|
-
new Response(null, {
|
|
139
|
-
status: redirection.status || 302,
|
|
140
|
-
headers: {
|
|
141
|
-
Location: redirection.url
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
];
|
|
145
|
-
}
|
|
146
87
|
return [
|
|
147
88
|
4,
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
Readable: void 0
|
|
151
|
-
};
|
|
152
|
-
})
|
|
89
|
+
requestHandler(request, requestHandlerOptions)
|
|
153
90
|
];
|
|
91
|
+
case 5:
|
|
92
|
+
response = _state.sent();
|
|
93
|
+
_state.label = 6;
|
|
154
94
|
case 6:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!(runtimeEnv === "node"))
|
|
158
|
-
return [
|
|
159
|
-
3,
|
|
160
|
-
8
|
|
161
|
-
];
|
|
162
|
-
return [
|
|
163
|
-
4,
|
|
164
|
-
import(streamModule).catch(function(_) {
|
|
165
|
-
return {
|
|
166
|
-
createReadableStreamFromReadable: void 0
|
|
167
|
-
};
|
|
168
|
-
})
|
|
169
|
-
];
|
|
170
|
-
case 7:
|
|
171
|
-
_tmp = _state.sent();
|
|
172
|
-
return [
|
|
173
|
-
3,
|
|
174
|
-
9
|
|
175
|
-
];
|
|
176
|
-
case 8:
|
|
177
|
-
_tmp = {
|
|
178
|
-
createReadableStreamFromReadable: void 0
|
|
179
|
-
};
|
|
180
|
-
_state.label = 9;
|
|
181
|
-
case 9:
|
|
182
|
-
createReadableStreamFromReadable = _tmp.createReadableStreamFromReadable;
|
|
183
|
-
data1 = Readable && _instanceof(ssrResult, Readable) ? (createReadableStreamFromReadable === null || createReadableStreamFromReadable === void 0 ? void 0 : createReadableStreamFromReadable(ssrResult)) || "" : ssrResult;
|
|
184
|
-
if (typeof data1 !== "string") {
|
|
185
|
-
responseProxy.headers.set("transfer-encoding", "chunked");
|
|
186
|
-
}
|
|
95
|
+
response.headers.set(X_MODERNJS_RENDER, "server");
|
|
96
|
+
response.headers.set("content-type", "text/html; charset=UTF-8");
|
|
187
97
|
return [
|
|
188
98
|
2,
|
|
189
|
-
|
|
190
|
-
status: responseProxy.status,
|
|
191
|
-
headers: responseProxy.headers
|
|
192
|
-
})
|
|
99
|
+
response
|
|
193
100
|
];
|
|
194
101
|
}
|
|
195
102
|
});
|
|
196
103
|
});
|
|
197
104
|
return _ssrRender.apply(this, arguments);
|
|
198
105
|
}
|
|
199
|
-
var ResponseProxy = function ResponseProxy2() {
|
|
200
|
-
"use strict";
|
|
201
|
-
_class_call_check(this, ResponseProxy2);
|
|
202
|
-
this.headers = new Headers();
|
|
203
|
-
this.status = 200;
|
|
204
|
-
this.headers.set("content-type", "text/html; charset=UTF-8");
|
|
205
|
-
};
|
|
206
106
|
var IncomingMessgeProxy = function IncomingMessgeProxy2(req) {
|
|
207
107
|
"use strict";
|
|
208
108
|
var _this = this;
|
|
@@ -214,38 +114,18 @@ var IncomingMessgeProxy = function IncomingMessgeProxy2(req) {
|
|
|
214
114
|
this.method = req.method;
|
|
215
115
|
this.url = getPathname(req);
|
|
216
116
|
};
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
host = nodeReq.headers.host;
|
|
229
|
-
}
|
|
230
|
-
host = host.split(/\s*,\s*/, 1)[0] || "undefined";
|
|
231
|
-
return host;
|
|
232
|
-
}
|
|
233
|
-
var href = "".concat(getProtocal(), "://").concat(getHost2()).concat(nodeReq.url || "");
|
|
234
|
-
return href;
|
|
235
|
-
}
|
|
236
|
-
function getPathnameFromNodeReq(nodeReq) {
|
|
237
|
-
var url = nodeReq.url;
|
|
238
|
-
if (!url) {
|
|
239
|
-
return "/";
|
|
240
|
-
}
|
|
241
|
-
var match = url.match(/\/[^?]*/);
|
|
242
|
-
var pathname = match ? match[0] : "/";
|
|
243
|
-
if (pathname !== "/" && pathname.endsWith("/")) {
|
|
244
|
-
pathname = pathname.slice(0, -1);
|
|
245
|
-
}
|
|
246
|
-
return pathname;
|
|
117
|
+
function createRequestHandlerConfig(userConfig) {
|
|
118
|
+
var output = userConfig.output, server = userConfig.server, security = userConfig.security, html = userConfig.html;
|
|
119
|
+
return {
|
|
120
|
+
ssr: server === null || server === void 0 ? void 0 : server.ssr,
|
|
121
|
+
ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
|
|
122
|
+
nonce: security === null || security === void 0 ? void 0 : security.nonce,
|
|
123
|
+
enableInlineScripts: output === null || output === void 0 ? void 0 : output.enableInlineScripts,
|
|
124
|
+
enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
|
|
125
|
+
crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
|
|
126
|
+
scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading
|
|
127
|
+
};
|
|
247
128
|
}
|
|
248
129
|
export {
|
|
249
|
-
getPathnameFromNodeReq,
|
|
250
130
|
ssrRender
|
|
251
131
|
};
|
|
File without changes
|
package/dist/esm/utils/error.js
CHANGED
|
@@ -15,11 +15,11 @@ var ErrorDigest;
|
|
|
15
15
|
ErrorDigest2["EINTER"] = "Internal server error";
|
|
16
16
|
ErrorDigest2["ERENDER"] = "SSR render failed";
|
|
17
17
|
})(ErrorDigest || (ErrorDigest = {}));
|
|
18
|
-
function onError(digest, error,
|
|
18
|
+
function onError(digest, error, monitors, req) {
|
|
19
19
|
var headerData = req && parseHeaders(req);
|
|
20
20
|
headerData && delete headerData.cookie;
|
|
21
|
-
if (
|
|
22
|
-
|
|
21
|
+
if (monitors) {
|
|
22
|
+
monitors.error(req ? "Server Error - ".concat(digest, ", error = %s, req.url = %s, req.headers = %o") : "Server Error - ".concat(digest, ", error = %s"), _instanceof(error, Error) ? error.stack || error.message : error, req === null || req === void 0 ? void 0 : req.url, headerData);
|
|
23
23
|
} else if (req) {
|
|
24
24
|
console.error("Server Error - ".concat(digest, ", error = ").concat(_instanceof(error, Error) ? error.stack || error.message : error, ", req.url = ").concat(req.url, ", req.headers = ").concat(JSON.stringify(headerData)));
|
|
25
25
|
} else {
|
|
@@ -6,17 +6,31 @@ function createTransformStream(fn) {
|
|
|
6
6
|
return new TransformStream({
|
|
7
7
|
transform: function transform(chunk, controller) {
|
|
8
8
|
return _async_to_generator(function() {
|
|
9
|
-
var content, newContent;
|
|
9
|
+
var content, newContent, _tmp;
|
|
10
10
|
return _ts_generator(this, function(_state) {
|
|
11
11
|
switch (_state.label) {
|
|
12
12
|
case 0:
|
|
13
13
|
content = decoder.decode(chunk);
|
|
14
|
+
if (!fn)
|
|
15
|
+
return [
|
|
16
|
+
3,
|
|
17
|
+
2
|
|
18
|
+
];
|
|
14
19
|
return [
|
|
15
20
|
4,
|
|
16
21
|
fn(content)
|
|
17
22
|
];
|
|
18
23
|
case 1:
|
|
19
|
-
|
|
24
|
+
_tmp = _state.sent();
|
|
25
|
+
return [
|
|
26
|
+
3,
|
|
27
|
+
3
|
|
28
|
+
];
|
|
29
|
+
case 2:
|
|
30
|
+
_tmp = content;
|
|
31
|
+
_state.label = 3;
|
|
32
|
+
case 3:
|
|
33
|
+
newContent = _tmp;
|
|
20
34
|
controller.enqueue(encoder.encode(newContent));
|
|
21
35
|
return [
|
|
22
36
|
2
|
|
@@ -40,7 +40,7 @@ const loadBundle = async (filepath, logger) => {
|
|
|
40
40
|
return void 0;
|
|
41
41
|
}
|
|
42
42
|
return dynamicImport(filepath).catch((e) => {
|
|
43
|
-
logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
|
|
43
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`Load ${filepath} bundle failed, error = %s`, e instanceof Error ? e.stack || e.message : e);
|
|
44
44
|
return void 0;
|
|
45
45
|
});
|
|
46
46
|
};
|