@modern-js/server-core 2.63.3 → 2.63.4
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/plugins/render/render.js +2 -15
- package/dist/cjs/plugins/render/ssrCache.js +5 -4
- package/dist/esm/plugins/render/render.js +5 -22
- package/dist/esm/plugins/render/ssrCache.js +2 -1
- package/dist/esm-node/plugins/render/render.js +4 -17
- package/dist/esm-node/plugins/render/ssrCache.js +2 -1
- package/package.json +7 -7
|
@@ -158,12 +158,6 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
158
158
|
}
|
|
159
159
|
async function renderHandler(request, options, mode, onError) {
|
|
160
160
|
var _options_config_server;
|
|
161
|
-
const serverData = {
|
|
162
|
-
router: {
|
|
163
|
-
baseUrl: options.routeInfo.urlPath,
|
|
164
|
-
params: options.params
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
161
|
let response = null;
|
|
168
162
|
const { serverManifest } = options;
|
|
169
163
|
const ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
|
|
@@ -198,10 +192,9 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
198
192
|
} else {
|
|
199
193
|
response = csrRender(options.html);
|
|
200
194
|
}
|
|
201
|
-
const newRes = (0, import_utils2.transformResponse)(response, injectServerData(serverData));
|
|
202
195
|
const { routeInfo } = options;
|
|
203
|
-
applyExtendHeaders(
|
|
204
|
-
return
|
|
196
|
+
applyExtendHeaders(response, routeInfo);
|
|
197
|
+
return response;
|
|
205
198
|
function applyExtendHeaders(r, route) {
|
|
206
199
|
Object.entries(route.responseHeaders || {}).forEach(([k, v]) => {
|
|
207
200
|
r.headers.set(k, v);
|
|
@@ -236,12 +229,6 @@ function csrRender(html) {
|
|
|
236
229
|
})
|
|
237
230
|
});
|
|
238
231
|
}
|
|
239
|
-
function injectServerData(serverData) {
|
|
240
|
-
const { head } = import_constants.REPLACE_REG.before;
|
|
241
|
-
const searchValue = new RegExp(head);
|
|
242
|
-
const replcaeCb = (beforeHead) => `${beforeHead}<script type="application/json" id="__MODERN_SERVER_DATA__">${JSON.stringify(serverData)}</script>`;
|
|
243
|
-
return (template) => template.replace(searchValue, replcaeCb);
|
|
244
|
-
}
|
|
245
232
|
// Annotate the CommonJS export names for ESM import in node:
|
|
246
233
|
0 && (module.exports = {
|
|
247
234
|
createRender
|
|
@@ -23,8 +23,9 @@ __export(ssrCache_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(ssrCache_exports);
|
|
25
25
|
var import_storer = require("@modern-js/runtime-utils/storer");
|
|
26
|
+
var import_utils = require("@modern-js/utils");
|
|
26
27
|
var import_constants = require("../../constants");
|
|
27
|
-
var
|
|
28
|
+
var import_utils2 = require("../../utils");
|
|
28
29
|
const ZERO_RENDER_LEVEL = /"renderLevel":0/;
|
|
29
30
|
const NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
|
|
30
31
|
async function processCache({ request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus }) {
|
|
@@ -32,7 +33,7 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
|
|
|
32
33
|
const { onError } = requestHandlerOptions;
|
|
33
34
|
const decoder = new TextDecoder();
|
|
34
35
|
if (response.body) {
|
|
35
|
-
const stream = (0,
|
|
36
|
+
const stream = (0, import_utils2.createTransformStream)();
|
|
36
37
|
const reader = response.body.getReader();
|
|
37
38
|
const writer = stream.writable.getWriter();
|
|
38
39
|
let html = "";
|
|
@@ -77,9 +78,9 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
|
|
|
77
78
|
const CACHE_NAMESPACE = "__ssr__cache";
|
|
78
79
|
const storage = (0, import_storer.createMemoryStorage)(CACHE_NAMESPACE);
|
|
79
80
|
function computedKey(req, cacheControl) {
|
|
80
|
-
const pathname = (0,
|
|
81
|
+
const pathname = (0, import_utils2.getPathname)(req);
|
|
81
82
|
const { customKey } = cacheControl;
|
|
82
|
-
const defaultKey = pathname
|
|
83
|
+
const defaultKey = pathname === "/" ? pathname : (0, import_utils.removeTailSlash)(pathname);
|
|
83
84
|
if (customKey) {
|
|
84
85
|
if (typeof customKey === "string") {
|
|
85
86
|
return customKey;
|
|
@@ -8,9 +8,9 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
|
8
8
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
9
9
|
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
|
10
10
|
import { TrieRouter } from "hono/router/trie-router";
|
|
11
|
-
import {
|
|
11
|
+
import { X_MODERNJS_RENDER } from "../../constants";
|
|
12
12
|
import { uniqueKeyByRoute } from "../../utils";
|
|
13
|
-
import { ErrorDigest, createErrorHtml, getPathname, getRuntimeEnv, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes
|
|
13
|
+
import { ErrorDigest, createErrorHtml, getPathname, getRuntimeEnv, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes } from "../../utils";
|
|
14
14
|
import { dataHandler } from "./dataHandler";
|
|
15
15
|
import { ssrRender } from "./ssrRender";
|
|
16
16
|
var DYNAMIC_ROUTE_REG = /\/:./;
|
|
@@ -264,7 +264,7 @@ function renderHandler(request, options, mode, onError) {
|
|
|
264
264
|
}
|
|
265
265
|
function _renderHandler() {
|
|
266
266
|
_renderHandler = _async_to_generator(function(request, options, mode, onError) {
|
|
267
|
-
var _options_config_server,
|
|
267
|
+
var _options_config_server, response, serverManifest, ssrByRouteIds, runtimeEnv, nestedRoutesJson, routes, urlPath, pathToFileURL, matchRoutes, url, matchedRoutes, _lastMatch_route, lastMatch, e, routeInfo;
|
|
268
268
|
function applyExtendHeaders(r, route) {
|
|
269
269
|
Object.entries(route.responseHeaders || {}).forEach(function(param) {
|
|
270
270
|
var _param = _sliced_to_array(param, 2), k = _param[0], v = _param[1];
|
|
@@ -274,12 +274,6 @@ function _renderHandler() {
|
|
|
274
274
|
return _ts_generator(this, function(_state) {
|
|
275
275
|
switch (_state.label) {
|
|
276
276
|
case 0:
|
|
277
|
-
serverData = {
|
|
278
|
-
router: {
|
|
279
|
-
baseUrl: options.routeInfo.urlPath,
|
|
280
|
-
params: options.params
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
277
|
response = null;
|
|
284
278
|
serverManifest = options.serverManifest;
|
|
285
279
|
ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
|
|
@@ -367,12 +361,11 @@ function _renderHandler() {
|
|
|
367
361
|
response = csrRender(options.html);
|
|
368
362
|
_state.label = 10;
|
|
369
363
|
case 10:
|
|
370
|
-
newRes = transformResponse(response, injectServerData(serverData));
|
|
371
364
|
routeInfo = options.routeInfo;
|
|
372
|
-
applyExtendHeaders(
|
|
365
|
+
applyExtendHeaders(response, routeInfo);
|
|
373
366
|
return [
|
|
374
367
|
2,
|
|
375
|
-
|
|
368
|
+
response
|
|
376
369
|
];
|
|
377
370
|
}
|
|
378
371
|
});
|
|
@@ -460,16 +453,6 @@ function csrRender(html) {
|
|
|
460
453
|
}, X_MODERNJS_RENDER, "client"))
|
|
461
454
|
});
|
|
462
455
|
}
|
|
463
|
-
function injectServerData(serverData) {
|
|
464
|
-
var head = REPLACE_REG.before.head;
|
|
465
|
-
var searchValue = new RegExp(head);
|
|
466
|
-
var replcaeCb = function(beforeHead) {
|
|
467
|
-
return "".concat(beforeHead, '<script type="application/json" id="__MODERN_SERVER_DATA__">').concat(JSON.stringify(serverData), "</script>");
|
|
468
|
-
};
|
|
469
|
-
return function(template) {
|
|
470
|
-
return template.replace(searchValue, replcaeCb);
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
456
|
export {
|
|
474
457
|
createRender
|
|
475
458
|
};
|
|
@@ -4,6 +4,7 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
4
4
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
6
|
import { createMemoryStorage } from "@modern-js/runtime-utils/storer";
|
|
7
|
+
import { removeTailSlash } from "@modern-js/utils";
|
|
7
8
|
import { X_RENDER_CACHE } from "../../constants";
|
|
8
9
|
import { createTransformStream, getPathname } from "../../utils";
|
|
9
10
|
var ZERO_RENDER_LEVEL = /"renderLevel":0/;
|
|
@@ -87,7 +88,7 @@ var storage = createMemoryStorage(CACHE_NAMESPACE);
|
|
|
87
88
|
function computedKey(req, cacheControl) {
|
|
88
89
|
var pathname = getPathname(req);
|
|
89
90
|
var customKey = cacheControl.customKey;
|
|
90
|
-
var defaultKey = pathname
|
|
91
|
+
var defaultKey = pathname === "/" ? pathname : removeTailSlash(pathname);
|
|
91
92
|
if (customKey) {
|
|
92
93
|
if (typeof customKey === "string") {
|
|
93
94
|
return customKey;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cutNameByHyphen } from "@modern-js/utils/universal";
|
|
2
2
|
import { TrieRouter } from "hono/router/trie-router";
|
|
3
|
-
import {
|
|
3
|
+
import { X_MODERNJS_RENDER } from "../../constants";
|
|
4
4
|
import { uniqueKeyByRoute } from "../../utils";
|
|
5
|
-
import { ErrorDigest, createErrorHtml, getPathname, getRuntimeEnv, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes
|
|
5
|
+
import { ErrorDigest, createErrorHtml, getPathname, getRuntimeEnv, onError as onErrorFn, parseHeaders, parseQuery, sortRoutes } from "../../utils";
|
|
6
6
|
import { dataHandler } from "./dataHandler";
|
|
7
7
|
import { ssrRender } from "./ssrRender";
|
|
8
8
|
const DYNAMIC_ROUTE_REG = /\/:./;
|
|
@@ -125,12 +125,6 @@ async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig
|
|
|
125
125
|
}
|
|
126
126
|
async function renderHandler(request, options, mode, onError) {
|
|
127
127
|
var _options_config_server;
|
|
128
|
-
const serverData = {
|
|
129
|
-
router: {
|
|
130
|
-
baseUrl: options.routeInfo.urlPath,
|
|
131
|
-
params: options.params
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
128
|
let response = null;
|
|
135
129
|
const { serverManifest } = options;
|
|
136
130
|
const ssrByRouteIds = (_options_config_server = options.config.server) === null || _options_config_server === void 0 ? void 0 : _options_config_server.ssrByRouteIds;
|
|
@@ -165,10 +159,9 @@ async function renderHandler(request, options, mode, onError) {
|
|
|
165
159
|
} else {
|
|
166
160
|
response = csrRender(options.html);
|
|
167
161
|
}
|
|
168
|
-
const newRes = transformResponse(response, injectServerData(serverData));
|
|
169
162
|
const { routeInfo } = options;
|
|
170
|
-
applyExtendHeaders(
|
|
171
|
-
return
|
|
163
|
+
applyExtendHeaders(response, routeInfo);
|
|
164
|
+
return response;
|
|
172
165
|
function applyExtendHeaders(r, route) {
|
|
173
166
|
Object.entries(route.responseHeaders || {}).forEach(([k, v]) => {
|
|
174
167
|
r.headers.set(k, v);
|
|
@@ -203,12 +196,6 @@ function csrRender(html) {
|
|
|
203
196
|
})
|
|
204
197
|
});
|
|
205
198
|
}
|
|
206
|
-
function injectServerData(serverData) {
|
|
207
|
-
const { head } = REPLACE_REG.before;
|
|
208
|
-
const searchValue = new RegExp(head);
|
|
209
|
-
const replcaeCb = (beforeHead) => `${beforeHead}<script type="application/json" id="__MODERN_SERVER_DATA__">${JSON.stringify(serverData)}</script>`;
|
|
210
|
-
return (template) => template.replace(searchValue, replcaeCb);
|
|
211
|
-
}
|
|
212
199
|
export {
|
|
213
200
|
createRender
|
|
214
201
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createMemoryStorage } from "@modern-js/runtime-utils/storer";
|
|
2
|
+
import { removeTailSlash } from "@modern-js/utils";
|
|
2
3
|
import { X_RENDER_CACHE } from "../../constants";
|
|
3
4
|
import { createTransformStream, getPathname } from "../../utils";
|
|
4
5
|
const ZERO_RENDER_LEVEL = /"renderLevel":0/;
|
|
@@ -55,7 +56,7 @@ const storage = createMemoryStorage(CACHE_NAMESPACE);
|
|
|
55
56
|
function computedKey(req, cacheControl) {
|
|
56
57
|
const pathname = getPathname(req);
|
|
57
58
|
const { customKey } = cacheControl;
|
|
58
|
-
const defaultKey = pathname
|
|
59
|
+
const defaultKey = pathname === "/" ? pathname : removeTailSlash(pathname);
|
|
59
60
|
if (customKey) {
|
|
60
61
|
if (typeof customKey === "string") {
|
|
61
62
|
return customKey;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.63.
|
|
18
|
+
"version": "2.63.4",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"flatted": "^3.2.9",
|
|
54
54
|
"hono": "^3.12.2",
|
|
55
55
|
"ts-deepmerge": "7.0.2",
|
|
56
|
-
"@modern-js/
|
|
57
|
-
"@modern-js/utils": "2.63.
|
|
58
|
-
"@modern-js/
|
|
56
|
+
"@modern-js/plugin": "2.63.4",
|
|
57
|
+
"@modern-js/runtime-utils": "2.63.4",
|
|
58
|
+
"@modern-js/utils": "2.63.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/jest": "^29",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"jest": "^29",
|
|
66
66
|
"ts-jest": "^29.1.0",
|
|
67
67
|
"typescript": "^5",
|
|
68
|
-
"@
|
|
69
|
-
"@scripts/
|
|
70
|
-
"@
|
|
68
|
+
"@modern-js/types": "2.63.4",
|
|
69
|
+
"@scripts/build": "2.63.4",
|
|
70
|
+
"@scripts/jest-config": "2.63.4"
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"publishConfig": {
|