@modern-js/server-core 2.63.2 → 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/adapters/node/plugins/resource.js +8 -3
- package/dist/cjs/plugins/render/render.js +2 -15
- package/dist/cjs/plugins/render/ssrCache.js +5 -4
- package/dist/cjs/plugins/render/ssrRender.js +3 -2
- package/dist/esm/adapters/node/plugins/resource.js +9 -5
- package/dist/esm/plugins/render/render.js +5 -22
- package/dist/esm/plugins/render/ssrCache.js +2 -1
- package/dist/esm/plugins/render/ssrRender.js +3 -2
- package/dist/esm-node/adapters/node/plugins/resource.js +9 -4
- package/dist/esm-node/plugins/render/render.js +4 -17
- package/dist/esm-node/plugins/render/ssrCache.js +2 -1
- package/dist/esm-node/plugins/render/ssrRender.js +3 -2
- package/dist/types/adapters/node/plugins/resource.d.ts +1 -1
- package/dist/types/types/config/source.d.ts +1 -0
- package/dist/types/types/requestHandler.d.ts +2 -1
- package/package.json +7 -7
|
@@ -56,10 +56,10 @@ async function getHtmlTemplates(pwd, routes) {
|
|
|
56
56
|
const templates = Object.fromEntries(htmls);
|
|
57
57
|
return templates;
|
|
58
58
|
}
|
|
59
|
-
function injectTemplates(pwd, routes) {
|
|
59
|
+
function injectTemplates(pwd, routes, htmlTemplatePromise) {
|
|
60
60
|
return async (c, next) => {
|
|
61
61
|
if (routes && !c.get("templates")) {
|
|
62
|
-
const templates = await getHtmlTemplates(pwd, routes);
|
|
62
|
+
const templates = await (htmlTemplatePromise || getHtmlTemplates(pwd, routes));
|
|
63
63
|
c.set("templates", templates);
|
|
64
64
|
}
|
|
65
65
|
await next();
|
|
@@ -119,13 +119,18 @@ const injectResourcePlugin = () => ({
|
|
|
119
119
|
return {
|
|
120
120
|
async prepare() {
|
|
121
121
|
const { middlewares, routes, distDirectory: pwd } = api.useAppContext();
|
|
122
|
+
let htmlTemplatePromise;
|
|
123
|
+
if ((0, import_utils.isProd)()) {
|
|
124
|
+
getServerManifest(pwd, routes || [], console);
|
|
125
|
+
htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
|
|
126
|
+
}
|
|
122
127
|
middlewares.push({
|
|
123
128
|
name: "inject-server-manifest",
|
|
124
129
|
handler: injectServerManifest(pwd, routes)
|
|
125
130
|
});
|
|
126
131
|
middlewares.push({
|
|
127
132
|
name: "inject-html",
|
|
128
|
-
handler: injectTemplates(pwd, routes)
|
|
133
|
+
handler: injectTemplates(pwd, routes, htmlTemplatePromise)
|
|
129
134
|
});
|
|
130
135
|
}
|
|
131
136
|
};
|
|
@@ -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;
|
|
@@ -91,7 +91,7 @@ class IncomingMessgeProxy {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function createRequestHandlerConfig(userConfig) {
|
|
94
|
-
const { output, server, security, html } = userConfig;
|
|
94
|
+
const { output, server, security, html, source } = userConfig;
|
|
95
95
|
return {
|
|
96
96
|
ssr: server === null || server === void 0 ? void 0 : server.ssr,
|
|
97
97
|
ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
|
|
@@ -100,7 +100,8 @@ function createRequestHandlerConfig(userConfig) {
|
|
|
100
100
|
enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
|
|
101
101
|
crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
|
|
102
102
|
scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
|
|
103
|
-
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
|
|
103
|
+
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
|
|
104
|
+
enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
6
|
-
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
|
|
6
|
+
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire, isProd } from "@modern-js/utils";
|
|
7
7
|
import { uniqueKeyByRoute } from "../../../utils";
|
|
8
8
|
function getHtmlTemplates(pwd, routes) {
|
|
9
9
|
return _getHtmlTemplates.apply(this, arguments);
|
|
@@ -73,7 +73,7 @@ function _getHtmlTemplates() {
|
|
|
73
73
|
});
|
|
74
74
|
return _getHtmlTemplates.apply(this, arguments);
|
|
75
75
|
}
|
|
76
|
-
function injectTemplates(pwd, routes) {
|
|
76
|
+
function injectTemplates(pwd, routes, htmlTemplatePromise) {
|
|
77
77
|
return function() {
|
|
78
78
|
var _ref = _async_to_generator(function(c, next) {
|
|
79
79
|
var templates;
|
|
@@ -87,7 +87,7 @@ function injectTemplates(pwd, routes) {
|
|
|
87
87
|
];
|
|
88
88
|
return [
|
|
89
89
|
4,
|
|
90
|
-
getHtmlTemplates(pwd, routes)
|
|
90
|
+
htmlTemplatePromise || getHtmlTemplates(pwd, routes)
|
|
91
91
|
];
|
|
92
92
|
case 1:
|
|
93
93
|
templates = _state.sent();
|
|
@@ -331,16 +331,20 @@ var injectResourcePlugin = function() {
|
|
|
331
331
|
return {
|
|
332
332
|
prepare: function prepare() {
|
|
333
333
|
return _async_to_generator(function() {
|
|
334
|
-
var _api_useAppContext, middlewares, routes, pwd;
|
|
334
|
+
var _api_useAppContext, middlewares, routes, pwd, htmlTemplatePromise;
|
|
335
335
|
return _ts_generator(this, function(_state) {
|
|
336
336
|
_api_useAppContext = api.useAppContext(), middlewares = _api_useAppContext.middlewares, routes = _api_useAppContext.routes, pwd = _api_useAppContext.distDirectory;
|
|
337
|
+
if (isProd()) {
|
|
338
|
+
getServerManifest(pwd, routes || [], console);
|
|
339
|
+
htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
|
|
340
|
+
}
|
|
337
341
|
middlewares.push({
|
|
338
342
|
name: "inject-server-manifest",
|
|
339
343
|
handler: injectServerManifest(pwd, routes)
|
|
340
344
|
});
|
|
341
345
|
middlewares.push({
|
|
342
346
|
name: "inject-html",
|
|
343
|
-
handler: injectTemplates(pwd, routes)
|
|
347
|
+
handler: injectTemplates(pwd, routes, htmlTemplatePromise)
|
|
344
348
|
});
|
|
345
349
|
return [
|
|
346
350
|
2
|
|
@@ -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;
|
|
@@ -115,7 +115,7 @@ var IncomingMessgeProxy = function IncomingMessgeProxy2(req) {
|
|
|
115
115
|
this.url = getPathname(req);
|
|
116
116
|
};
|
|
117
117
|
function createRequestHandlerConfig(userConfig) {
|
|
118
|
-
var output = userConfig.output, server = userConfig.server, security = userConfig.security, html = userConfig.html;
|
|
118
|
+
var output = userConfig.output, server = userConfig.server, security = userConfig.security, html = userConfig.html, source = userConfig.source;
|
|
119
119
|
return {
|
|
120
120
|
ssr: server === null || server === void 0 ? void 0 : server.ssr,
|
|
121
121
|
ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
|
|
@@ -124,7 +124,8 @@ function createRequestHandlerConfig(userConfig) {
|
|
|
124
124
|
enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
|
|
125
125
|
crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
|
|
126
126
|
scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
|
|
127
|
-
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
|
|
127
|
+
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
|
|
128
|
+
enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
131
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
3
|
-
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
|
|
3
|
+
import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire, isProd } from "@modern-js/utils";
|
|
4
4
|
import { uniqueKeyByRoute } from "../../../utils";
|
|
5
5
|
async function getHtmlTemplates(pwd, routes) {
|
|
6
6
|
const htmls = await Promise.all(routes.map(async (route) => {
|
|
@@ -19,10 +19,10 @@ async function getHtmlTemplates(pwd, routes) {
|
|
|
19
19
|
const templates = Object.fromEntries(htmls);
|
|
20
20
|
return templates;
|
|
21
21
|
}
|
|
22
|
-
function injectTemplates(pwd, routes) {
|
|
22
|
+
function injectTemplates(pwd, routes, htmlTemplatePromise) {
|
|
23
23
|
return async (c, next) => {
|
|
24
24
|
if (routes && !c.get("templates")) {
|
|
25
|
-
const templates = await getHtmlTemplates(pwd, routes);
|
|
25
|
+
const templates = await (htmlTemplatePromise || getHtmlTemplates(pwd, routes));
|
|
26
26
|
c.set("templates", templates);
|
|
27
27
|
}
|
|
28
28
|
await next();
|
|
@@ -82,13 +82,18 @@ const injectResourcePlugin = () => ({
|
|
|
82
82
|
return {
|
|
83
83
|
async prepare() {
|
|
84
84
|
const { middlewares, routes, distDirectory: pwd } = api.useAppContext();
|
|
85
|
+
let htmlTemplatePromise;
|
|
86
|
+
if (isProd()) {
|
|
87
|
+
getServerManifest(pwd, routes || [], console);
|
|
88
|
+
htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
|
|
89
|
+
}
|
|
85
90
|
middlewares.push({
|
|
86
91
|
name: "inject-server-manifest",
|
|
87
92
|
handler: injectServerManifest(pwd, routes)
|
|
88
93
|
});
|
|
89
94
|
middlewares.push({
|
|
90
95
|
name: "inject-html",
|
|
91
|
-
handler: injectTemplates(pwd, routes)
|
|
96
|
+
handler: injectTemplates(pwd, routes, htmlTemplatePromise)
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
99
|
};
|
|
@@ -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;
|
|
@@ -68,7 +68,7 @@ class IncomingMessgeProxy {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
function createRequestHandlerConfig(userConfig) {
|
|
71
|
-
const { output, server, security, html } = userConfig;
|
|
71
|
+
const { output, server, security, html, source } = userConfig;
|
|
72
72
|
return {
|
|
73
73
|
ssr: server === null || server === void 0 ? void 0 : server.ssr,
|
|
74
74
|
ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
|
|
@@ -77,7 +77,8 @@ function createRequestHandlerConfig(userConfig) {
|
|
|
77
77
|
enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
|
|
78
78
|
crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
|
|
79
79
|
scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
|
|
80
|
-
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
|
|
80
|
+
useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
|
|
81
|
+
enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Logger, ServerRoute } from '@modern-js/types';
|
|
2
2
|
import type { Middleware, ServerEnv, ServerManifest, ServerPlugin } from '../../../types';
|
|
3
3
|
export declare function getHtmlTemplates(pwd: string, routes: ServerRoute[]): Promise<Record<string, string>>;
|
|
4
|
-
export declare function injectTemplates(pwd: string, routes?: ServerRoute[]): Middleware<ServerEnv>;
|
|
4
|
+
export declare function injectTemplates(pwd: string, routes?: ServerRoute[], htmlTemplatePromise?: ReturnType<typeof getHtmlTemplates>): Middleware<ServerEnv>;
|
|
5
5
|
export declare function getServerManifest(pwd: string, routes: ServerRoute[], logger: Logger): Promise<ServerManifest>;
|
|
6
6
|
export declare function injectServerManifest(pwd: string, routes?: ServerRoute[]): Middleware<ServerEnv>;
|
|
7
7
|
export declare const injectResourcePlugin: () => ServerPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
|
|
2
|
-
import type { ServerUserConfig } from './config';
|
|
2
|
+
import type { ServerUserConfig, SourceUserConfig } from './config';
|
|
3
3
|
export type Resource = {
|
|
4
4
|
loadableStats: Record<string, any>;
|
|
5
5
|
routeManifest: Record<string, any>;
|
|
@@ -17,6 +17,7 @@ export type RequestHandlerConfig = {
|
|
|
17
17
|
ssr?: ServerUserConfig['ssr'];
|
|
18
18
|
ssrByEntries?: ServerUserConfig['ssrByEntries'];
|
|
19
19
|
useJsonScript?: ServerUserConfig['useJsonScript'];
|
|
20
|
+
enableAsyncEntry?: SourceUserConfig['enableAsyncEntry'];
|
|
20
21
|
};
|
|
21
22
|
export type LoaderContext = Map<string, any>;
|
|
22
23
|
export type OnError = (err: unknown) => void;
|
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/
|
|
58
|
-
"@modern-js/utils": "2.63.
|
|
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
|
-
"@
|
|
70
|
-
"@scripts/jest-config": "2.63.
|
|
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": {
|