@modern-js/server-core 2.63.5 → 2.63.7

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.
@@ -57,6 +57,7 @@ class CustomServer {
57
57
  const rewriteRoute = routes.find((route) => route.entryName === current);
58
58
  if (rewriteRoute) {
59
59
  c.set("matchPathname", rewriteRoute.urlPath);
60
+ c.set("matchEntryName", current);
60
61
  }
61
62
  }
62
63
  if (c.finalized) {
@@ -92,6 +92,7 @@ function createRenderHandler(render) {
92
92
  const locals = c.get("locals");
93
93
  const metrics = c.get("metrics");
94
94
  const matchPathname = c.get("matchPathname");
95
+ const matchEntryName = c.get("matchEntryName");
95
96
  const loaderContext = (0, import_helper.getLoaderCtx)(c);
96
97
  const request = c.req.raw;
97
98
  const nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
@@ -105,7 +106,8 @@ function createRenderHandler(render) {
105
106
  serverManifest,
106
107
  loaderContext,
107
108
  locals,
108
- matchPathname
109
+ matchPathname,
110
+ matchEntryName
109
111
  });
110
112
  const { body, status, headers } = res;
111
113
  const headersData = {};
@@ -61,10 +61,16 @@ function getRouter(routes) {
61
61
  }
62
62
  return router;
63
63
  }
64
- function matchRoute(router, pathname) {
64
+ function matchRoute(router, pathname, entryName) {
65
65
  const matched = router.match("*", pathname);
66
- const result = matched[0][0];
67
- return result || [];
66
+ if (entryName && matched[0].length > 1) {
67
+ const matches = matched[0];
68
+ const result = matches.find(([route]) => route.entryName === entryName);
69
+ return result || [];
70
+ } else {
71
+ const result = matched[0][0];
72
+ return result || [];
73
+ }
68
74
  }
69
75
  function getHeadersWithoutCookie(headers) {
70
76
  const _headers = {
@@ -76,9 +82,9 @@ function getHeadersWithoutCookie(headers) {
76
82
  }
77
83
  async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn }) {
78
84
  const router = getRouter(routes);
79
- return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext }) => {
85
+ return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchEntryName, matchPathname, loaderContext }) => {
80
86
  const forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : (0, import_utils2.getPathname)(req);
81
- const [routeInfo, params] = matchRoute(router, forMatchpathname);
87
+ const [routeInfo, params] = matchRoute(router, forMatchpathname, matchEntryName);
82
88
  const framework = metaName || "modern-js";
83
89
  const fallbackHeader = `x-${(0, import_universal.cutNameByHyphen)(framework)}-ssr-fallback`;
84
90
  let fallbackReason = null;
@@ -23,9 +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");
27
26
  var import_constants = require("../../constants");
28
- var import_utils2 = require("../../utils");
27
+ var import_utils = require("../../utils");
28
+ const removeTailSlash = (s) => s.replace(/\/+$/, "");
29
29
  const ZERO_RENDER_LEVEL = /"renderLevel":0/;
30
30
  const NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
31
31
  async function processCache({ request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus }) {
@@ -33,7 +33,7 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
33
33
  const { onError } = requestHandlerOptions;
34
34
  const decoder = new TextDecoder();
35
35
  if (response.body) {
36
- const stream = (0, import_utils2.createTransformStream)();
36
+ const stream = (0, import_utils.createTransformStream)();
37
37
  const reader = response.body.getReader();
38
38
  const writer = stream.writable.getWriter();
39
39
  let html = "";
@@ -78,9 +78,9 @@ async function processCache({ request, key, requestHandler, requestHandlerOption
78
78
  const CACHE_NAMESPACE = "__ssr__cache";
79
79
  const storage = (0, import_storer.createMemoryStorage)(CACHE_NAMESPACE);
80
80
  function computedKey(req, cacheControl) {
81
- const pathname = (0, import_utils2.getPathname)(req);
81
+ const pathname = (0, import_utils.getPathname)(req);
82
82
  const { customKey } = cacheControl;
83
- const defaultKey = pathname === "/" ? pathname : (0, import_utils.removeTailSlash)(pathname);
83
+ const defaultKey = pathname === "/" ? pathname : removeTailSlash(pathname);
84
84
  if (customKey) {
85
85
  if (typeof customKey === "string") {
86
86
  return customKey;
@@ -72,6 +72,7 @@ var CustomServer = /* @__PURE__ */ function() {
72
72
  });
73
73
  if (rewriteRoute) {
74
74
  c.set("matchPathname", rewriteRoute.urlPath);
75
+ c.set("matchEntryName", current);
75
76
  }
76
77
  }
77
78
  if (c.finalized) {
@@ -133,7 +133,7 @@ function getPageRoutes(routes) {
133
133
  function createRenderHandler(render) {
134
134
  return function() {
135
135
  var _ref = _async_to_generator(function(c, _) {
136
- var _c_env_node, logger, reporter, monitors, templates, serverManifest, locals, metrics, matchPathname, loaderContext, request, nodeReq, res, body, status, headers, headersData;
136
+ var _c_env_node, logger, reporter, monitors, templates, serverManifest, locals, metrics, matchPathname, matchEntryName, loaderContext, request, nodeReq, res, body, status, headers, headersData;
137
137
  return _ts_generator(this, function(_state) {
138
138
  switch (_state.label) {
139
139
  case 0:
@@ -145,6 +145,7 @@ function createRenderHandler(render) {
145
145
  locals = c.get("locals");
146
146
  metrics = c.get("metrics");
147
147
  matchPathname = c.get("matchPathname");
148
+ matchEntryName = c.get("matchEntryName");
148
149
  loaderContext = getLoaderCtx(c);
149
150
  request = c.req.raw;
150
151
  nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
@@ -160,7 +161,8 @@ function createRenderHandler(render) {
160
161
  serverManifest,
161
162
  loaderContext,
162
163
  locals,
163
- matchPathname
164
+ matchPathname,
165
+ matchEntryName
164
166
  })
165
167
  ];
166
168
  case 1:
@@ -50,10 +50,19 @@ function getRouter(routes) {
50
50
  }
51
51
  return router;
52
52
  }
53
- function matchRoute(router, pathname) {
53
+ function matchRoute(router, pathname, entryName) {
54
54
  var matched = router.match("*", pathname);
55
- var result = matched[0][0];
56
- return result || [];
55
+ if (entryName && matched[0].length > 1) {
56
+ var matches = matched[0];
57
+ var result = matches.find(function(param) {
58
+ var _param = _sliced_to_array(param, 1), route = _param[0];
59
+ return route.entryName === entryName;
60
+ });
61
+ return result || [];
62
+ } else {
63
+ var result1 = matched[0][0];
64
+ return result1 || [];
65
+ }
57
66
  }
58
67
  function getHeadersWithoutCookie(headers) {
59
68
  var _headers = _object_spread_props(_object_spread({}, headers), {
@@ -75,13 +84,13 @@ function _createRender() {
75
84
  2,
76
85
  function() {
77
86
  var _ref = _async_to_generator(function(req, param2) {
78
- var logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext, forMatchpathname, _matchRoute, routeInfo, params, framework, fallbackHeader, fallbackReason, onFallback, html, renderMode, headerData, onError, onTiming, onBoundError, renderOptions, response, _tmp;
87
+ var logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchEntryName, matchPathname, loaderContext, forMatchpathname, _matchRoute, routeInfo, params, framework, fallbackHeader, fallbackReason, onFallback, html, renderMode, headerData, onError, onTiming, onBoundError, renderOptions, response, _tmp;
79
88
  return _ts_generator(this, function(_state2) {
80
89
  switch (_state2.label) {
81
90
  case 0:
82
- logger = param2.logger, reporter = param2.reporter, metrics = param2.metrics, monitors = param2.monitors, nodeReq = param2.nodeReq, templates = param2.templates, serverManifest = param2.serverManifest, locals = param2.locals, matchPathname = param2.matchPathname, loaderContext = param2.loaderContext;
91
+ logger = param2.logger, reporter = param2.reporter, metrics = param2.metrics, monitors = param2.monitors, nodeReq = param2.nodeReq, templates = param2.templates, serverManifest = param2.serverManifest, locals = param2.locals, matchEntryName = param2.matchEntryName, matchPathname = param2.matchPathname, loaderContext = param2.loaderContext;
83
92
  forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : getPathname(req);
84
- _matchRoute = _sliced_to_array(matchRoute(router, forMatchpathname), 2), routeInfo = _matchRoute[0], params = _matchRoute[1];
93
+ _matchRoute = _sliced_to_array(matchRoute(router, forMatchpathname, matchEntryName), 2), routeInfo = _matchRoute[0], params = _matchRoute[1];
85
94
  framework = metaName || "modern-js";
86
95
  fallbackHeader = "x-".concat(cutNameByHyphen(framework), "-ssr-fallback");
87
96
  fallbackReason = null;
@@ -4,9 +4,11 @@ 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";
8
7
  import { X_RENDER_CACHE } from "../../constants";
9
8
  import { createTransformStream, getPathname } from "../../utils";
9
+ var removeTailSlash = function(s) {
10
+ return s.replace(/\/+$/, "");
11
+ };
10
12
  var ZERO_RENDER_LEVEL = /"renderLevel":0/;
11
13
  var NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
12
14
  function processCache(_) {
@@ -32,6 +32,7 @@ class CustomServer {
32
32
  const rewriteRoute = routes.find((route) => route.entryName === current);
33
33
  if (rewriteRoute) {
34
34
  c.set("matchPathname", rewriteRoute.urlPath);
35
+ c.set("matchEntryName", current);
35
36
  }
36
37
  }
37
38
  if (c.finalized) {
@@ -68,6 +68,7 @@ function createRenderHandler(render) {
68
68
  const locals = c.get("locals");
69
69
  const metrics = c.get("metrics");
70
70
  const matchPathname = c.get("matchPathname");
71
+ const matchEntryName = c.get("matchEntryName");
71
72
  const loaderContext = getLoaderCtx(c);
72
73
  const request = c.req.raw;
73
74
  const nodeReq = (_c_env_node = c.env.node) === null || _c_env_node === void 0 ? void 0 : _c_env_node.req;
@@ -81,7 +82,8 @@ function createRenderHandler(render) {
81
82
  serverManifest,
82
83
  loaderContext,
83
84
  locals,
84
- matchPathname
85
+ matchPathname,
86
+ matchEntryName
85
87
  });
86
88
  const { body, status, headers } = res;
87
89
  const headersData = {};
@@ -28,10 +28,16 @@ function getRouter(routes) {
28
28
  }
29
29
  return router;
30
30
  }
31
- function matchRoute(router, pathname) {
31
+ function matchRoute(router, pathname, entryName) {
32
32
  const matched = router.match("*", pathname);
33
- const result = matched[0][0];
34
- return result || [];
33
+ if (entryName && matched[0].length > 1) {
34
+ const matches = matched[0];
35
+ const result = matches.find(([route]) => route.entryName === entryName);
36
+ return result || [];
37
+ } else {
38
+ const result = matched[0][0];
39
+ return result || [];
40
+ }
35
41
  }
36
42
  function getHeadersWithoutCookie(headers) {
37
43
  const _headers = {
@@ -43,9 +49,9 @@ function getHeadersWithoutCookie(headers) {
43
49
  }
44
50
  async function createRender({ routes, pwd, metaName, staticGenerate, cacheConfig, forceCSR, config, onFallback: onFallbackFn }) {
45
51
  const router = getRouter(routes);
46
- return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchPathname, loaderContext }) => {
52
+ return async (req, { logger, reporter, metrics, monitors, nodeReq, templates, serverManifest, locals, matchEntryName, matchPathname, loaderContext }) => {
47
53
  const forMatchpathname = matchPathname !== null && matchPathname !== void 0 ? matchPathname : getPathname(req);
48
- const [routeInfo, params] = matchRoute(router, forMatchpathname);
54
+ const [routeInfo, params] = matchRoute(router, forMatchpathname, matchEntryName);
49
55
  const framework = metaName || "modern-js";
50
56
  const fallbackHeader = `x-${cutNameByHyphen(framework)}-ssr-fallback`;
51
57
  let fallbackReason = null;
@@ -1,7 +1,7 @@
1
1
  import { createMemoryStorage } from "@modern-js/runtime-utils/storer";
2
- import { removeTailSlash } from "@modern-js/utils";
3
2
  import { X_RENDER_CACHE } from "../../constants";
4
3
  import { createTransformStream, getPathname } from "../../utils";
4
+ const removeTailSlash = (s) => s.replace(/\/+$/, "");
5
5
  const ZERO_RENDER_LEVEL = /"renderLevel":0/;
6
6
  const NO_SSR_CACHE = /<meta\s+[^>]*name=["']no-ssr-cache["'][^>]*>/i;
7
7
  async function processCache({ request, key, requestHandler, requestHandlerOptions, ttl, container, cacheStatus }) {
@@ -5,5 +5,6 @@ export interface BffUserConfig {
5
5
  proxy?: Record<string, Options>;
6
6
  httpMethodDecider?: HttpMethodDecider;
7
7
  enableHandleWeb?: boolean;
8
+ enableCrossProjectInvocation?: boolean;
8
9
  }
9
10
  export type BffNormalizedConfig = BffUserConfig;
@@ -16,6 +16,8 @@ export interface RenderOptions {
16
16
  reporter?: Reporter;
17
17
  /** For compat rewrite MPA, while not modify request */
18
18
  matchPathname?: string;
19
+ /** For compat rewrite MPA, while not modify request */
20
+ matchEntryName?: string;
19
21
  monitors?: Monitors;
20
22
  serverManifest: ServerManifest;
21
23
  nodeReq?: IncomingMessage;
@@ -36,6 +36,7 @@ type ServerVariables = {
36
36
  serverManifest?: ServerManifest;
37
37
  templates?: Record<string, string>;
38
38
  matchPathname?: string;
39
+ matchEntryName?: string;
39
40
  /**
40
41
  * Communicating with custom server hook & modern ssrContext.
41
42
  *
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.5",
18
+ "version": "2.63.7",
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/plugin": "2.63.5",
57
- "@modern-js/runtime-utils": "2.63.5",
58
- "@modern-js/utils": "2.63.5"
56
+ "@modern-js/plugin": "2.63.7",
57
+ "@modern-js/runtime-utils": "2.63.7",
58
+ "@modern-js/utils": "2.63.7"
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
- "@modern-js/types": "2.63.5",
69
- "@scripts/build": "2.63.5",
70
- "@scripts/jest-config": "2.63.5"
68
+ "@modern-js/types": "2.63.7",
69
+ "@scripts/build": "2.63.7",
70
+ "@scripts/jest-config": "2.63.7"
71
71
  },
72
72
  "sideEffects": false,
73
73
  "publishConfig": {