@modern-js/server-core 3.10.4 → 3.11.1

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.
@@ -54,12 +54,11 @@ var ServerTimings = /*#__PURE__*/ function(ServerTimings) {
54
54
  const SERVER_TIMING = 'Server-Timing';
55
55
  const X_RENDER_CACHE = 'x-render-cache';
56
56
  const X_MODERNJS_RENDER = 'x-modernjs-render';
57
- __webpack_require__.d(__webpack_exports__, {
58
- ServerTimings: ()=>ServerTimings
59
- }, {
57
+ __webpack_require__.d(__webpack_exports__, {}, {
60
58
  AGGRED_DIR: AGGRED_DIR,
61
59
  REPLACE_REG: REPLACE_REG,
62
60
  SERVER_TIMING: SERVER_TIMING,
61
+ ServerTimings: ServerTimings,
63
62
  X_MODERNJS_RENDER: X_MODERNJS_RENDER,
64
63
  X_RENDER_CACHE: X_RENDER_CACHE
65
64
  });
@@ -37,8 +37,8 @@ function getLoaderCtx(c) {
37
37
  return loaderContext;
38
38
  }
39
39
  }
40
- __webpack_require__.d(__webpack_exports__, {
41
- getLoaderCtx: ()=>getLoaderCtx
40
+ __webpack_require__.d(__webpack_exports__, {}, {
41
+ getLoaderCtx: getLoaderCtx
42
42
  });
43
43
  exports.getLoaderCtx = __webpack_exports__.getLoaderCtx;
44
44
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -65,10 +65,10 @@ function handleSetupResult(setupResult, api) {
65
65
  }
66
66
  });
67
67
  }
68
- __webpack_require__.d(__webpack_exports__, {
69
- getHookRunners: ()=>getHookRunners,
70
- handleSetupResult: ()=>handleSetupResult,
71
- transformHookRunner: ()=>transformHookRunner
68
+ __webpack_require__.d(__webpack_exports__, {}, {
69
+ getHookRunners: getHookRunners,
70
+ handleSetupResult: handleSetupResult,
71
+ transformHookRunner: transformHookRunner
72
72
  });
73
73
  exports.getHookRunners = __webpack_exports__.getHookRunners;
74
74
  exports.handleSetupResult = __webpack_exports__.handleSetupResult;
@@ -82,8 +82,12 @@ var __webpack_exports__ = {};
82
82
  handler: (0, _monitors__rspack_import_2.requestLatencyMiddleware)()
83
83
  });
84
84
  for (const route of pageRoutes){
85
- const { urlPath: originUrlPath } = route;
86
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
85
+ const urlPath = (0, _utils__rspack_import_1.getRoutePath)(route);
86
+ if (route.isSSG && !urlPath.endsWith('/')) middlewares.push({
87
+ name: 'ssg-trailing-slash-redirect',
88
+ path: `${urlPath}/`,
89
+ handler: async (c)=>c.redirect(`${urlPath}${new URL(c.req.url).search}`, 308)
90
+ });
87
91
  renderMiddlewares?.forEach((m)=>{
88
92
  middlewares.push({
89
93
  name: m.name,
@@ -70,8 +70,7 @@ var __webpack_exports__ = {};
70
70
  ];
71
71
  const router = new trie_router_namespaceObject.TrieRouter();
72
72
  for (const route of finalRoutes){
73
- const { urlPath: originUrlPath } = route;
74
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
73
+ const urlPath = (0, index_js_namespaceObject.getRoutePath)(route);
75
74
  router.add('*', urlPath, route);
76
75
  }
77
76
  return router;
@@ -41,8 +41,8 @@ function createRequestHandlerConfig(userConfig) {
41
41
  enableAsyncEntry: source?.enableAsyncEntry
42
42
  };
43
43
  }
44
- __webpack_require__.d(__webpack_exports__, {
45
- createRequestHandlerConfig: ()=>createRequestHandlerConfig
44
+ __webpack_require__.d(__webpack_exports__, {}, {
45
+ createRequestHandlerConfig: createRequestHandlerConfig
46
46
  });
47
47
  exports.createRequestHandlerConfig = __webpack_exports__.createRequestHandlerConfig;
48
48
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -50,7 +50,7 @@ const injectRoutePlugin = ()=>({
50
50
  const pageRoutes = getPageRoutes(routes);
51
51
  for (const route of pageRoutes){
52
52
  const { urlPath: originUrlPath, entryName = constants_namespaceObject.MAIN_ENTRY_NAME } = route;
53
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
53
+ const urlPath = (0, index_js_namespaceObject.getRoutePath)(route);
54
54
  middlewares.push({
55
55
  name: 'inject-route-info',
56
56
  path: urlPath,
@@ -29,13 +29,20 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  const sortRoutes = (route1, route2)=>route2.urlPath.length - route1.urlPath.length;
31
31
  const uniqueKeyByRoute = (route)=>`${route.entryName}-${route.urlPath}`;
32
+ const getRoutePath = ({ urlPath, isSSG })=>{
33
+ if (isSSG) return urlPath;
34
+ return urlPath.endsWith('/') ? `${urlPath}*` : `${urlPath}/*`;
35
+ };
32
36
  __webpack_require__.d(__webpack_exports__, {}, {
37
+ getRoutePath: getRoutePath,
33
38
  sortRoutes: sortRoutes,
34
39
  uniqueKeyByRoute: uniqueKeyByRoute
35
40
  });
41
+ exports.getRoutePath = __webpack_exports__.getRoutePath;
36
42
  exports.sortRoutes = __webpack_exports__.sortRoutes;
37
43
  exports.uniqueKeyByRoute = __webpack_exports__.uniqueKeyByRoute;
38
44
  for(var __rspack_i in __webpack_exports__)if (-1 === [
45
+ "getRoutePath",
39
46
  "sortRoutes",
40
47
  "uniqueKeyByRoute"
41
48
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -66,12 +66,12 @@ function parseCookie(req) {
66
66
  });
67
67
  return cookie;
68
68
  }
69
- __webpack_require__.d(__webpack_exports__, {
70
- getHost: ()=>getHost,
71
- getPathname: ()=>getPathname,
72
- parseCookie: ()=>parseCookie,
73
- parseHeaders: ()=>parseHeaders,
74
- parseQuery: ()=>parseQuery
69
+ __webpack_require__.d(__webpack_exports__, {}, {
70
+ getHost: getHost,
71
+ getPathname: getPathname,
72
+ parseCookie: parseCookie,
73
+ parseHeaders: parseHeaders,
74
+ parseQuery: parseQuery
75
75
  });
76
76
  exports.getHost = __webpack_exports__.getHost;
77
77
  exports.getPathname = __webpack_exports__.getPathname;
@@ -54,9 +54,9 @@ function transformResponse(response, transformCb) {
54
54
  statusText: response.statusText
55
55
  });
56
56
  }
57
- __webpack_require__.d(__webpack_exports__, {
58
- createTransformStream: ()=>createTransformStream,
59
- transformResponse: ()=>transformResponse
57
+ __webpack_require__.d(__webpack_exports__, {}, {
58
+ createTransformStream: createTransformStream,
59
+ transformResponse: transformResponse
60
60
  });
61
61
  exports.createTransformStream = __webpack_exports__.createTransformStream;
62
62
  exports.transformResponse = __webpack_exports__.transformResponse;
@@ -32,8 +32,8 @@ function warmup(bundles) {
32
32
  bundle && import(bundle).catch((_)=>{});
33
33
  });
34
34
  }
35
- __webpack_require__.d(__webpack_exports__, {
36
- warmup: ()=>warmup
35
+ __webpack_require__.d(__webpack_exports__, {}, {
36
+ warmup: warmup
37
37
  });
38
38
  exports.warmup = __webpack_exports__.warmup;
39
39
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -1,3 +1,3 @@
1
1
  import { createStorage } from "./utils/storage.mjs";
2
- const { run: run, useHonoContext: useHonoContext } = createStorage('@modern-js/server-core/hono-context');
2
+ const { run, useHonoContext } = createStorage('@modern-js/server-core/hono-context');
3
3
  export { run, useHonoContext };
@@ -1,5 +1,5 @@
1
1
  import { getLoaderCtx } from "../../helper.mjs";
2
- import { sortRoutes } from "../../utils/index.mjs";
2
+ import { getRoutePath, sortRoutes } from "../../utils/index.mjs";
3
3
  import { requestLatencyMiddleware } from "../monitors.mjs";
4
4
  export * from "./inject.mjs";
5
5
  const renderPlugin = ()=>({
@@ -14,8 +14,12 @@ const renderPlugin = ()=>({
14
14
  handler: requestLatencyMiddleware()
15
15
  });
16
16
  for (const route of pageRoutes){
17
- const { urlPath: originUrlPath } = route;
18
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
17
+ const urlPath = getRoutePath(route);
18
+ if (route.isSSG && !urlPath.endsWith('/')) middlewares.push({
19
+ name: 'ssg-trailing-slash-redirect',
20
+ path: `${urlPath}/`,
21
+ handler: async (c)=>c.redirect(`${urlPath}${new URL(c.req.url).search}`, 308)
22
+ });
19
23
  renderMiddlewares?.forEach((m)=>{
20
24
  middlewares.push({
21
25
  name: m.name,
@@ -2,7 +2,7 @@ import { cutNameByHyphen } from "@modern-js/utils/universal";
2
2
  import { TrieRouter } from "hono/router/trie-router";
3
3
  import { getPath } from "hono/utils/url";
4
4
  import { X_MODERNJS_RENDER } from "../../constants.mjs";
5
- import { ErrorDigest, createErrorHtml, getRuntimeEnv, parseHeaders, parseQuery, sortRoutes, uniqueKeyByRoute } from "../../utils/index.mjs";
5
+ import { ErrorDigest, createErrorHtml, getRoutePath, getRuntimeEnv, parseHeaders, parseQuery, sortRoutes, uniqueKeyByRoute } from "../../utils/index.mjs";
6
6
  import { csrRscRender } from "./csrRscRender.mjs";
7
7
  import { dataHandler } from "./dataHandler.mjs";
8
8
  import { renderRscHandler } from "./renderRscHandler.mjs";
@@ -22,8 +22,7 @@ function getRouter(routes) {
22
22
  ];
23
23
  const router = new TrieRouter();
24
24
  for (const route of finalRoutes){
25
- const { urlPath: originUrlPath } = route;
26
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
25
+ const urlPath = getRoutePath(route);
27
26
  router.add('*', urlPath, route);
28
27
  }
29
28
  return router;
@@ -1,5 +1,5 @@
1
1
  import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
2
- import { sortRoutes } from "../utils/index.mjs";
2
+ import { getRoutePath, sortRoutes } from "../utils/index.mjs";
3
3
  function injectRoute(route) {
4
4
  return async (c, next)=>{
5
5
  if (route && !c.get('route')) c.set('route', route);
@@ -18,7 +18,7 @@ const injectRoutePlugin = ()=>({
18
18
  const pageRoutes = getPageRoutes(routes);
19
19
  for (const route of pageRoutes){
20
20
  const { urlPath: originUrlPath, entryName = MAIN_ENTRY_NAME } = route;
21
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
21
+ const urlPath = getRoutePath(route);
22
22
  middlewares.push({
23
23
  name: 'inject-route-info',
24
24
  path: urlPath,
@@ -1,3 +1,7 @@
1
1
  const sortRoutes = (route1, route2)=>route2.urlPath.length - route1.urlPath.length;
2
2
  const uniqueKeyByRoute = (route)=>`${route.entryName}-${route.urlPath}`;
3
- export { sortRoutes, uniqueKeyByRoute };
3
+ const getRoutePath = ({ urlPath, isSSG })=>{
4
+ if (isSSG) return urlPath;
5
+ return urlPath.endsWith('/') ? `${urlPath}*` : `${urlPath}/*`;
6
+ };
7
+ export { getRoutePath, sortRoutes, uniqueKeyByRoute };
@@ -1,4 +1,4 @@
1
1
  import "node:module";
2
2
  import { createStorage } from "./utils/storage.mjs";
3
- const { run: run, useHonoContext: useHonoContext } = createStorage('@modern-js/server-core/hono-context');
3
+ const { run, useHonoContext } = createStorage('@modern-js/server-core/hono-context');
4
4
  export { run, useHonoContext };
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { getLoaderCtx } from "../../helper.mjs";
3
- import { sortRoutes } from "../../utils/index.mjs";
3
+ import { getRoutePath, sortRoutes } from "../../utils/index.mjs";
4
4
  import { requestLatencyMiddleware } from "../monitors.mjs";
5
5
  export * from "./inject.mjs";
6
6
  const renderPlugin = ()=>({
@@ -15,8 +15,12 @@ const renderPlugin = ()=>({
15
15
  handler: requestLatencyMiddleware()
16
16
  });
17
17
  for (const route of pageRoutes){
18
- const { urlPath: originUrlPath } = route;
19
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
18
+ const urlPath = getRoutePath(route);
19
+ if (route.isSSG && !urlPath.endsWith('/')) middlewares.push({
20
+ name: 'ssg-trailing-slash-redirect',
21
+ path: `${urlPath}/`,
22
+ handler: async (c)=>c.redirect(`${urlPath}${new URL(c.req.url).search}`, 308)
23
+ });
20
24
  renderMiddlewares?.forEach((m)=>{
21
25
  middlewares.push({
22
26
  name: m.name,
@@ -3,7 +3,7 @@ import { cutNameByHyphen } from "@modern-js/utils/universal";
3
3
  import { TrieRouter } from "hono/router/trie-router";
4
4
  import { getPath } from "hono/utils/url";
5
5
  import { X_MODERNJS_RENDER } from "../../constants.mjs";
6
- import { ErrorDigest, createErrorHtml, getRuntimeEnv, parseHeaders, parseQuery, sortRoutes, uniqueKeyByRoute } from "../../utils/index.mjs";
6
+ import { ErrorDigest, createErrorHtml, getRoutePath, getRuntimeEnv, parseHeaders, parseQuery, sortRoutes, uniqueKeyByRoute } from "../../utils/index.mjs";
7
7
  import { csrRscRender } from "./csrRscRender.mjs";
8
8
  import { dataHandler } from "./dataHandler.mjs";
9
9
  import { renderRscHandler } from "./renderRscHandler.mjs";
@@ -25,8 +25,7 @@ function getRouter(routes) {
25
25
  ];
26
26
  const router = new TrieRouter();
27
27
  for (const route of finalRoutes){
28
- const { urlPath: originUrlPath } = route;
29
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
28
+ const urlPath = getRoutePath(route);
30
29
  router.add('*', urlPath, route);
31
30
  }
32
31
  return router;
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { MAIN_ENTRY_NAME } from "@modern-js/utils/universal/constants";
3
- import { sortRoutes } from "../utils/index.mjs";
3
+ import { getRoutePath, sortRoutes } from "../utils/index.mjs";
4
4
  function injectRoute(route) {
5
5
  return async (c, next)=>{
6
6
  if (route && !c.get('route')) c.set('route', route);
@@ -19,7 +19,7 @@ const injectRoutePlugin = ()=>({
19
19
  const pageRoutes = getPageRoutes(routes);
20
20
  for (const route of pageRoutes){
21
21
  const { urlPath: originUrlPath, entryName = MAIN_ENTRY_NAME } = route;
22
- const urlPath = originUrlPath.endsWith('/') ? `${originUrlPath}*` : `${originUrlPath}/*`;
22
+ const urlPath = getRoutePath(route);
23
23
  middlewares.push({
24
24
  name: 'inject-route-info',
25
25
  path: urlPath,
@@ -1,4 +1,8 @@
1
1
  import "node:module";
2
2
  const sortRoutes = (route1, route2)=>route2.urlPath.length - route1.urlPath.length;
3
3
  const uniqueKeyByRoute = (route)=>`${route.entryName}-${route.urlPath}`;
4
- export { sortRoutes, uniqueKeyByRoute };
4
+ const getRoutePath = ({ urlPath, isSSG })=>{
5
+ if (isSSG) return urlPath;
6
+ return urlPath.endsWith('/') ? `${urlPath}*` : `${urlPath}/*`;
7
+ };
8
+ export { getRoutePath, sortRoutes, uniqueKeyByRoute };
@@ -1,3 +1,4 @@
1
1
  import type { ServerRoute } from '@modern-js/types';
2
2
  export declare const sortRoutes: (route1: ServerRoute, route2: ServerRoute) => number;
3
3
  export declare const uniqueKeyByRoute: (route: ServerRoute) => string;
4
+ export declare const getRoutePath: ({ urlPath, isSSG }: ServerRoute) => string;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.10.4",
18
+ "version": "3.11.1",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "exports": {
@@ -71,9 +71,9 @@
71
71
  "flatted": "^3.4.4",
72
72
  "hono": "^4.11.7",
73
73
  "ts-deepmerge": "8.0.0",
74
- "@modern-js/plugin": "3.10.4",
75
- "@modern-js/runtime-utils": "3.10.4",
76
- "@modern-js/utils": "3.10.4"
74
+ "@modern-js/plugin": "3.11.1",
75
+ "@modern-js/runtime-utils": "3.11.1",
76
+ "@modern-js/utils": "3.11.1"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/cloneable-readable": "^2.0.3",
@@ -81,9 +81,9 @@
81
81
  "@types/node": "^20",
82
82
  "http-proxy-middleware": "^2.0.11",
83
83
  "typescript": "^5",
84
- "@modern-js/types": "3.10.4",
85
- "@modern-js/rslib": "3.10.4",
86
- "@scripts/rstest-config": "2.66.3"
84
+ "@modern-js/types": "3.11.1",
85
+ "@scripts/rstest-config": "2.66.5",
86
+ "@modern-js/rslib": "3.11.1"
87
87
  },
88
88
  "sideEffects": false,
89
89
  "publishConfig": {