@modern-js/server-core 3.9.2 → 3.9.3
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/node.js +3 -1
- package/dist/cjs/plugins/render/ssrCache.js +54 -20
- package/dist/esm/adapters/node/node.mjs +3 -1
- package/dist/esm/plugins/render/render.mjs +1 -7
- package/dist/esm/plugins/render/ssrCache.mjs +54 -20
- package/dist/esm-node/adapters/node/node.mjs +3 -1
- package/dist/esm-node/plugins/render/render.mjs +1 -7
- package/dist/esm-node/plugins/render/ssrCache.mjs +54 -20
- package/dist/types/adapters/node/plugins/static.d.ts +2 -2
- package/package.json +7 -7
- package/dist/esm/rslib-runtime~1.mjs +0 -18
- package/dist/esm-node/rslib-runtime~0.mjs +0 -19
|
@@ -68,7 +68,9 @@ const createWebRequest = (req, res, body)=>{
|
|
|
68
68
|
headers: headerRecord,
|
|
69
69
|
signal: controller.signal
|
|
70
70
|
};
|
|
71
|
-
res.on('close', ()=>
|
|
71
|
+
res.on('close', ()=>{
|
|
72
|
+
if (!res.writableFinished || req.aborted) controller.abort('res closed');
|
|
73
|
+
});
|
|
72
74
|
const url = `http://${req.headers.host}${req.url}`;
|
|
73
75
|
const needsRequestBody = body || !('GET' === method || 'HEAD' === method);
|
|
74
76
|
const cloneableReq = needsRequestBody ? external_cloneable_readable_default()(req) : null;
|
|
@@ -59,30 +59,59 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
|
|
|
59
59
|
const reader = response.body.getReader();
|
|
60
60
|
const writer = stream.writable.getWriter();
|
|
61
61
|
let html = '';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
let cancelled = false;
|
|
63
|
+
const cancel = async (reason)=>{
|
|
64
|
+
cancelled = true;
|
|
65
|
+
await reader.cancel(reason);
|
|
66
|
+
};
|
|
67
|
+
writer.closed.catch(cancel).catch(()=>{});
|
|
68
|
+
const onAbort = ()=>{
|
|
69
|
+
Promise.allSettled([
|
|
70
|
+
cancel(request.signal.reason),
|
|
71
|
+
writer.abort(request.signal.reason)
|
|
72
|
+
]);
|
|
73
|
+
};
|
|
74
|
+
request.signal.addEventListener('abort', onAbort, {
|
|
75
|
+
once: true
|
|
76
|
+
});
|
|
77
|
+
if (request.signal.aborted) onAbort();
|
|
78
|
+
const pumping = (async ()=>{
|
|
79
|
+
try {
|
|
80
|
+
for(;;){
|
|
81
|
+
const { done, value } = await reader.read();
|
|
82
|
+
if (cancelled) return;
|
|
83
|
+
if (done) break;
|
|
84
|
+
html += decoder.decode(value, {
|
|
85
|
+
stream: true
|
|
86
|
+
});
|
|
87
|
+
await writer.write(value);
|
|
88
|
+
}
|
|
89
|
+
html += decoder.decode();
|
|
90
|
+
await writer.close();
|
|
91
|
+
if (!cancelled && !ZERO_RENDER_LEVEL.test(html) && !NO_SSR_CACHE.test(html)) {
|
|
67
92
|
const cache = {
|
|
68
93
|
val: html,
|
|
69
|
-
cursor:
|
|
94
|
+
cursor: Date.now()
|
|
70
95
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
try {
|
|
97
|
+
await container.set(key, JSON.stringify(cache), {
|
|
98
|
+
ttl
|
|
99
|
+
});
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (onError) onError(error, 'render-cache');
|
|
102
|
+
else console.error(`[render-cache] set cache failed, key: ${key}`, error);
|
|
103
|
+
}
|
|
79
104
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
} catch (error) {
|
|
106
|
+
await Promise.allSettled([
|
|
107
|
+
cancel(error),
|
|
108
|
+
writer.abort(error)
|
|
109
|
+
]);
|
|
110
|
+
} finally{
|
|
111
|
+
request.signal.removeEventListener('abort', onAbort);
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
pumping.catch(()=>{});
|
|
86
115
|
cacheStatus && response.headers.set(external_constants_js_namespaceObject.X_RENDER_CACHE, cacheStatus);
|
|
87
116
|
return new Response(stream.readable, {
|
|
88
117
|
status: response.status,
|
|
@@ -178,6 +207,11 @@ async function getCacheResult(request, options) {
|
|
|
178
207
|
container
|
|
179
208
|
}).then(async (response)=>{
|
|
180
209
|
await response.text();
|
|
210
|
+
}).catch((error)=>{
|
|
211
|
+
try {
|
|
212
|
+
if (onError) onError(error, 'render-cache');
|
|
213
|
+
else console.error('[render-cache] revalidation failed', error);
|
|
214
|
+
} catch {}
|
|
181
215
|
});
|
|
182
216
|
const cacheStatus = 'stale';
|
|
183
217
|
return new Response(cache.val, {
|
|
@@ -24,7 +24,9 @@ const createWebRequest = (req, res, body)=>{
|
|
|
24
24
|
headers: headerRecord,
|
|
25
25
|
signal: controller.signal
|
|
26
26
|
};
|
|
27
|
-
res.on('close', ()=>
|
|
27
|
+
res.on('close', ()=>{
|
|
28
|
+
if (!res.writableFinished || req.aborted) controller.abort('res closed');
|
|
29
|
+
});
|
|
28
30
|
const url = `http://${req.headers.host}${req.url}`;
|
|
29
31
|
const needsRequestBody = body || !('GET' === method || 'HEAD' === method);
|
|
30
32
|
const cloneableReq = needsRequestBody ? cloneable_readable(req) : null;
|
|
@@ -7,12 +7,6 @@ import { dataHandler } from "./dataHandler.mjs";
|
|
|
7
7
|
import { renderRscHandler } from "./renderRscHandler.mjs";
|
|
8
8
|
import { serverActionHandler } from "./serverActionHandler.mjs";
|
|
9
9
|
import { ssrRender } from "./ssrRender.mjs";
|
|
10
|
-
import { __webpack_require__ } from "../../rslib-runtime~1.mjs";
|
|
11
|
-
__webpack_require__.add({
|
|
12
|
-
718 (module) {
|
|
13
|
-
module.exports = require("@modern-js/runtime-utils/router");
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
10
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
17
11
|
function getRouter(routes) {
|
|
18
12
|
const dynamicRoutes = [];
|
|
@@ -161,7 +155,7 @@ async function renderHandler(request, options, mode, fallbackWrapper, framework)
|
|
|
161
155
|
const { nestedRoutesJson } = serverManifest;
|
|
162
156
|
const routes = nestedRoutesJson?.[options.routeInfo.entryName];
|
|
163
157
|
if (routes) {
|
|
164
|
-
const { matchRoutes } =
|
|
158
|
+
const { matchRoutes } = require("@modern-js/runtime-utils/router");
|
|
165
159
|
const url = new URL(request.url);
|
|
166
160
|
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
167
161
|
if (matchedRoutes) {
|
|
@@ -25,30 +25,59 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
|
|
|
25
25
|
const reader = response.body.getReader();
|
|
26
26
|
const writer = stream.writable.getWriter();
|
|
27
27
|
let html = '';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
let cancelled = false;
|
|
29
|
+
const cancel = async (reason)=>{
|
|
30
|
+
cancelled = true;
|
|
31
|
+
await reader.cancel(reason);
|
|
32
|
+
};
|
|
33
|
+
writer.closed.catch(cancel).catch(()=>{});
|
|
34
|
+
const onAbort = ()=>{
|
|
35
|
+
Promise.allSettled([
|
|
36
|
+
cancel(request.signal.reason),
|
|
37
|
+
writer.abort(request.signal.reason)
|
|
38
|
+
]);
|
|
39
|
+
};
|
|
40
|
+
request.signal.addEventListener('abort', onAbort, {
|
|
41
|
+
once: true
|
|
42
|
+
});
|
|
43
|
+
if (request.signal.aborted) onAbort();
|
|
44
|
+
const pumping = (async ()=>{
|
|
45
|
+
try {
|
|
46
|
+
for(;;){
|
|
47
|
+
const { done, value } = await reader.read();
|
|
48
|
+
if (cancelled) return;
|
|
49
|
+
if (done) break;
|
|
50
|
+
html += decoder.decode(value, {
|
|
51
|
+
stream: true
|
|
52
|
+
});
|
|
53
|
+
await writer.write(value);
|
|
54
|
+
}
|
|
55
|
+
html += decoder.decode();
|
|
56
|
+
await writer.close();
|
|
57
|
+
if (!cancelled && !ZERO_RENDER_LEVEL.test(html) && !NO_SSR_CACHE.test(html)) {
|
|
33
58
|
const cache = {
|
|
34
59
|
val: html,
|
|
35
|
-
cursor:
|
|
60
|
+
cursor: Date.now()
|
|
36
61
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
try {
|
|
63
|
+
await container.set(key, JSON.stringify(cache), {
|
|
64
|
+
ttl
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (onError) onError(error, 'render-cache');
|
|
68
|
+
else console.error(`[render-cache] set cache failed, key: ${key}`, error);
|
|
69
|
+
}
|
|
45
70
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
} catch (error) {
|
|
72
|
+
await Promise.allSettled([
|
|
73
|
+
cancel(error),
|
|
74
|
+
writer.abort(error)
|
|
75
|
+
]);
|
|
76
|
+
} finally{
|
|
77
|
+
request.signal.removeEventListener('abort', onAbort);
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
pumping.catch(()=>{});
|
|
52
81
|
cacheStatus && response.headers.set(X_RENDER_CACHE, cacheStatus);
|
|
53
82
|
return new Response(stream.readable, {
|
|
54
83
|
status: response.status,
|
|
@@ -144,6 +173,11 @@ async function getCacheResult(request, options) {
|
|
|
144
173
|
container
|
|
145
174
|
}).then(async (response)=>{
|
|
146
175
|
await response.text();
|
|
176
|
+
}).catch((error)=>{
|
|
177
|
+
try {
|
|
178
|
+
if (onError) onError(error, 'render-cache');
|
|
179
|
+
else console.error('[render-cache] revalidation failed', error);
|
|
180
|
+
} catch {}
|
|
147
181
|
});
|
|
148
182
|
const cacheStatus = 'stale';
|
|
149
183
|
return new Response(cache.val, {
|
|
@@ -25,7 +25,9 @@ const createWebRequest = (req, res, body)=>{
|
|
|
25
25
|
headers: headerRecord,
|
|
26
26
|
signal: controller.signal
|
|
27
27
|
};
|
|
28
|
-
res.on('close', ()=>
|
|
28
|
+
res.on('close', ()=>{
|
|
29
|
+
if (!res.writableFinished || req.aborted) controller.abort('res closed');
|
|
30
|
+
});
|
|
29
31
|
const url = `http://${req.headers.host}${req.url}`;
|
|
30
32
|
const needsRequestBody = body || !('GET' === method || 'HEAD' === method);
|
|
31
33
|
const cloneableReq = needsRequestBody ? cloneable_readable(req) : null;
|
|
@@ -8,14 +8,8 @@ import { dataHandler } from "./dataHandler.mjs";
|
|
|
8
8
|
import { renderRscHandler } from "./renderRscHandler.mjs";
|
|
9
9
|
import { serverActionHandler } from "./serverActionHandler.mjs";
|
|
10
10
|
import { ssrRender } from "./ssrRender.mjs";
|
|
11
|
-
import { __webpack_require__ } from "../../rslib-runtime~0.mjs";
|
|
12
11
|
import { createRequire as __rspack_createRequire } from "node:module";
|
|
13
12
|
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
14
|
-
__webpack_require__.add({
|
|
15
|
-
"@modern-js/runtime-utils/router" (module) {
|
|
16
|
-
module.exports = __rspack_createRequire_require("@modern-js/runtime-utils/router");
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
13
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
20
14
|
function getRouter(routes) {
|
|
21
15
|
const dynamicRoutes = [];
|
|
@@ -164,7 +158,7 @@ async function renderHandler(request, options, mode, fallbackWrapper, framework)
|
|
|
164
158
|
const { nestedRoutesJson } = serverManifest;
|
|
165
159
|
const routes = nestedRoutesJson?.[options.routeInfo.entryName];
|
|
166
160
|
if (routes) {
|
|
167
|
-
const { matchRoutes } =
|
|
161
|
+
const { matchRoutes } = __rspack_createRequire_require("@modern-js/runtime-utils/router");
|
|
168
162
|
const url = new URL(request.url);
|
|
169
163
|
const matchedRoutes = matchRoutes(routes, url.pathname, options.routeInfo.urlPath);
|
|
170
164
|
if (matchedRoutes) {
|
|
@@ -26,30 +26,59 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
|
|
|
26
26
|
const reader = response.body.getReader();
|
|
27
27
|
const writer = stream.writable.getWriter();
|
|
28
28
|
let html = '';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
let cancelled = false;
|
|
30
|
+
const cancel = async (reason)=>{
|
|
31
|
+
cancelled = true;
|
|
32
|
+
await reader.cancel(reason);
|
|
33
|
+
};
|
|
34
|
+
writer.closed.catch(cancel).catch(()=>{});
|
|
35
|
+
const onAbort = ()=>{
|
|
36
|
+
Promise.allSettled([
|
|
37
|
+
cancel(request.signal.reason),
|
|
38
|
+
writer.abort(request.signal.reason)
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
request.signal.addEventListener('abort', onAbort, {
|
|
42
|
+
once: true
|
|
43
|
+
});
|
|
44
|
+
if (request.signal.aborted) onAbort();
|
|
45
|
+
const pumping = (async ()=>{
|
|
46
|
+
try {
|
|
47
|
+
for(;;){
|
|
48
|
+
const { done, value } = await reader.read();
|
|
49
|
+
if (cancelled) return;
|
|
50
|
+
if (done) break;
|
|
51
|
+
html += decoder.decode(value, {
|
|
52
|
+
stream: true
|
|
53
|
+
});
|
|
54
|
+
await writer.write(value);
|
|
55
|
+
}
|
|
56
|
+
html += decoder.decode();
|
|
57
|
+
await writer.close();
|
|
58
|
+
if (!cancelled && !ZERO_RENDER_LEVEL.test(html) && !NO_SSR_CACHE.test(html)) {
|
|
34
59
|
const cache = {
|
|
35
60
|
val: html,
|
|
36
|
-
cursor:
|
|
61
|
+
cursor: Date.now()
|
|
37
62
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
try {
|
|
64
|
+
await container.set(key, JSON.stringify(cache), {
|
|
65
|
+
ttl
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (onError) onError(error, 'render-cache');
|
|
69
|
+
else console.error(`[render-cache] set cache failed, key: ${key}`, error);
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
} catch (error) {
|
|
73
|
+
await Promise.allSettled([
|
|
74
|
+
cancel(error),
|
|
75
|
+
writer.abort(error)
|
|
76
|
+
]);
|
|
77
|
+
} finally{
|
|
78
|
+
request.signal.removeEventListener('abort', onAbort);
|
|
79
|
+
}
|
|
80
|
+
})();
|
|
81
|
+
pumping.catch(()=>{});
|
|
53
82
|
cacheStatus && response.headers.set(X_RENDER_CACHE, cacheStatus);
|
|
54
83
|
return new Response(stream.readable, {
|
|
55
84
|
status: response.status,
|
|
@@ -145,6 +174,11 @@ async function getCacheResult(request, options) {
|
|
|
145
174
|
container
|
|
146
175
|
}).then(async (response)=>{
|
|
147
176
|
await response.text();
|
|
177
|
+
}).catch((error)=>{
|
|
178
|
+
try {
|
|
179
|
+
if (onError) onError(error, 'render-cache');
|
|
180
|
+
else console.error('[render-cache] revalidation failed', error);
|
|
181
|
+
} catch {}
|
|
148
182
|
});
|
|
149
183
|
const cacheStatus = 'stale';
|
|
150
184
|
return new Response(cache.val, {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ServerRoute } from '@modern-js/types';
|
|
2
2
|
import type { HtmlNormalizedConfig, Middleware, OutputNormalizedConfig, ServerNormalizedConfig, ServerPlugin } from '../../../types/index.js';
|
|
3
3
|
export declare const serverStaticPlugin: () => ServerPlugin;
|
|
4
|
-
export type
|
|
4
|
+
export type PublicMiddlewareOptions = {
|
|
5
5
|
pwd: string;
|
|
6
6
|
routes: ServerRoute[];
|
|
7
7
|
};
|
|
8
|
-
export declare function createPublicMiddleware({ pwd, routes, }:
|
|
8
|
+
export declare function createPublicMiddleware({ pwd, routes, }: PublicMiddlewareOptions): Middleware;
|
|
9
9
|
export interface ServerStaticOptions {
|
|
10
10
|
pwd: string;
|
|
11
11
|
output: OutputNormalizedConfig;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.9.
|
|
18
|
+
"version": "3.9.3",
|
|
19
19
|
"types": "./dist/types/index.d.ts",
|
|
20
20
|
"main": "./dist/cjs/index.js",
|
|
21
21
|
"exports": {
|
|
@@ -70,20 +70,20 @@
|
|
|
70
70
|
"cloneable-readable": "^3.0.0",
|
|
71
71
|
"flatted": "^3.4.4",
|
|
72
72
|
"hono": "^4.11.7",
|
|
73
|
-
"ts-deepmerge": "
|
|
74
|
-
"@modern-js/plugin": "3.9.
|
|
75
|
-
"@modern-js/runtime-utils": "3.9.
|
|
76
|
-
"@modern-js/utils": "3.9.
|
|
73
|
+
"ts-deepmerge": "8.0.0",
|
|
74
|
+
"@modern-js/plugin": "3.9.3",
|
|
75
|
+
"@modern-js/runtime-utils": "3.9.3",
|
|
76
|
+
"@modern-js/utils": "3.9.3"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@rslib/core": "1.0.
|
|
79
|
+
"@rslib/core": "1.0.1",
|
|
80
80
|
"@types/cloneable-readable": "^2.0.3",
|
|
81
81
|
"@types/merge-deep": "^3.0.3",
|
|
82
82
|
"@types/node": "^20",
|
|
83
83
|
"http-proxy-middleware": "^2.0.10",
|
|
84
84
|
"typescript": "^5",
|
|
85
85
|
"@modern-js/rslib": "2.68.10",
|
|
86
|
-
"@modern-js/types": "3.9.
|
|
86
|
+
"@modern-js/types": "3.9.3",
|
|
87
87
|
"@scripts/rstest-config": "2.66.0"
|
|
88
88
|
},
|
|
89
89
|
"sideEffects": false,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __webpack_modules__ = {};
|
|
2
|
-
var __webpack_module_cache__ = {};
|
|
3
|
-
function __webpack_require__(moduleId) {
|
|
4
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
5
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
6
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
7
|
-
exports: {}
|
|
8
|
-
};
|
|
9
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
10
|
-
return module.exports;
|
|
11
|
-
}
|
|
12
|
-
__webpack_require__.m = __webpack_modules__;
|
|
13
|
-
(()=>{
|
|
14
|
-
__webpack_require__.add = function(modules) {
|
|
15
|
-
Object.assign(__webpack_require__.m, modules);
|
|
16
|
-
};
|
|
17
|
-
})();
|
|
18
|
-
export { __webpack_require__ };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
var __webpack_modules__ = {};
|
|
3
|
-
var __webpack_module_cache__ = {};
|
|
4
|
-
function __webpack_require__(moduleId) {
|
|
5
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
6
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
7
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
8
|
-
exports: {}
|
|
9
|
-
};
|
|
10
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
11
|
-
return module.exports;
|
|
12
|
-
}
|
|
13
|
-
__webpack_require__.m = __webpack_modules__;
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.add = function(modules) {
|
|
16
|
-
Object.assign(__webpack_require__.m, modules);
|
|
17
|
-
};
|
|
18
|
-
})();
|
|
19
|
-
export { __webpack_require__ };
|