@modern-js/server-core 2.67.4 → 2.67.6

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.
@@ -88,9 +88,23 @@ function matchPublicRoute(req, routes) {
88
88
  }
89
89
  return void 0;
90
90
  }
91
+ const extractPathname = (url) => {
92
+ try {
93
+ if (url.includes("://")) {
94
+ return new URL(url).pathname || "/";
95
+ }
96
+ if (url.startsWith("//")) {
97
+ return new URL(`http:${url}`).pathname || "/";
98
+ }
99
+ return url;
100
+ } catch (e) {
101
+ return url;
102
+ }
103
+ };
91
104
  function createStaticMiddleware(options) {
92
105
  const { pwd, routes } = options;
93
106
  const prefix = options.output.assetPrefix || "/";
107
+ const pathPrefix = extractPathname(prefix);
94
108
  const { distPath: { css: cssPath, js: jsPath, media: mediaPath } = {} } = options.output;
95
109
  const { favicon, faviconByEntries } = options.html;
96
110
  const favicons = prepareFavicons(favicon, faviconByEntries);
@@ -109,7 +123,7 @@ function createStaticMiddleware(options) {
109
123
  "icon.png",
110
124
  ...favicons
111
125
  ];
112
- const regPrefix = prefix.endsWith("/") ? prefix : `${prefix}/`;
126
+ const regPrefix = pathPrefix.endsWith("/") ? pathPrefix : `${pathPrefix}/`;
113
127
  const staticPathRegExp = new RegExp(`^${regPrefix}(${[
114
128
  ...staticReg,
115
129
  ...iconReg
@@ -122,7 +136,7 @@ function createStaticMiddleware(options) {
122
136
  }
123
137
  const hit = staticPathRegExp.test(pathname);
124
138
  if (hit) {
125
- const filepath = import_path.default.join(pwd, pathname.replace(prefix, () => ""));
139
+ const filepath = import_path.default.join(pwd, pathname.replace(pathPrefix, () => ""));
126
140
  if (!await import_utils.fs.pathExists(filepath)) {
127
141
  return next();
128
142
  }
@@ -41,7 +41,7 @@ async function ssrRender(request, { routeInfo, html, config: userConfig, staticG
41
41
  }
42
42
  const renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || import_constants.MAIN_ENTRY_NAME];
43
43
  if (!renderBundle) {
44
- throw new Error(`Can't found renderBundle ${entryName || import_constants.MAIN_ENTRY_NAME}`);
44
+ throw new Error(`Can't find renderBundle ${entryName || import_constants.MAIN_ENTRY_NAME}`);
45
45
  }
46
46
  const requestHandler = await renderBundle[SERVER_RUNTIME_ENTRY];
47
47
  const config = createRequestHandlerConfig(userConfig);
@@ -110,9 +110,23 @@ function matchPublicRoute(req, routes) {
110
110
  }
111
111
  return void 0;
112
112
  }
113
+ var extractPathname = function(url) {
114
+ try {
115
+ if (url.includes("://")) {
116
+ return new URL(url).pathname || "/";
117
+ }
118
+ if (url.startsWith("//")) {
119
+ return new URL("http:".concat(url)).pathname || "/";
120
+ }
121
+ return url;
122
+ } catch (e) {
123
+ return url;
124
+ }
125
+ };
113
126
  function createStaticMiddleware(options) {
114
127
  var pwd = options.pwd, routes = options.routes;
115
128
  var prefix = options.output.assetPrefix || "/";
129
+ var pathPrefix = extractPathname(prefix);
116
130
  var _options_output = options.output, tmp = _options_output.distPath, _ref = tmp === void 0 ? {} : tmp, cssPath = _ref.css, jsPath = _ref.js, mediaPath = _ref.media;
117
131
  var _options_html = options.html, favicon = _options_html.favicon, faviconByEntries = _options_html.faviconByEntries;
118
132
  var favicons = prepareFavicons(favicon, faviconByEntries);
@@ -131,7 +145,7 @@ function createStaticMiddleware(options) {
131
145
  "favicon.ico",
132
146
  "icon.png"
133
147
  ].concat(_to_consumable_array(favicons));
134
- var regPrefix = prefix.endsWith("/") ? prefix : "".concat(prefix, "/");
148
+ var regPrefix = pathPrefix.endsWith("/") ? pathPrefix : "".concat(pathPrefix, "/");
135
149
  var staticPathRegExp = new RegExp("^".concat(regPrefix, "(").concat(_to_consumable_array(staticReg).concat(_to_consumable_array(iconReg)).join("|"), ")"));
136
150
  return function() {
137
151
  var _ref2 = _async_to_generator(function(c, next) {
@@ -153,7 +167,7 @@ function createStaticMiddleware(options) {
153
167
  3,
154
168
  4
155
169
  ];
156
- filepath = path.join(pwd, pathname.replace(prefix, function() {
170
+ filepath = path.join(pwd, pathname.replace(pathPrefix, function() {
157
171
  return "";
158
172
  }));
159
173
  return [
@@ -29,7 +29,7 @@ function _ssrRender() {
29
29
  }
30
30
  renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
31
31
  if (!renderBundle) {
32
- throw new Error("Can't found renderBundle ".concat(entryName || MAIN_ENTRY_NAME));
32
+ throw new Error("Can't find renderBundle ".concat(entryName || MAIN_ENTRY_NAME));
33
33
  }
34
34
  return [
35
35
  4,
@@ -53,9 +53,23 @@ function matchPublicRoute(req, routes) {
53
53
  }
54
54
  return void 0;
55
55
  }
56
+ const extractPathname = (url) => {
57
+ try {
58
+ if (url.includes("://")) {
59
+ return new URL(url).pathname || "/";
60
+ }
61
+ if (url.startsWith("//")) {
62
+ return new URL(`http:${url}`).pathname || "/";
63
+ }
64
+ return url;
65
+ } catch (e) {
66
+ return url;
67
+ }
68
+ };
56
69
  function createStaticMiddleware(options) {
57
70
  const { pwd, routes } = options;
58
71
  const prefix = options.output.assetPrefix || "/";
72
+ const pathPrefix = extractPathname(prefix);
59
73
  const { distPath: { css: cssPath, js: jsPath, media: mediaPath } = {} } = options.output;
60
74
  const { favicon, faviconByEntries } = options.html;
61
75
  const favicons = prepareFavicons(favicon, faviconByEntries);
@@ -74,7 +88,7 @@ function createStaticMiddleware(options) {
74
88
  "icon.png",
75
89
  ...favicons
76
90
  ];
77
- const regPrefix = prefix.endsWith("/") ? prefix : `${prefix}/`;
91
+ const regPrefix = pathPrefix.endsWith("/") ? pathPrefix : `${pathPrefix}/`;
78
92
  const staticPathRegExp = new RegExp(`^${regPrefix}(${[
79
93
  ...staticReg,
80
94
  ...iconReg
@@ -87,7 +101,7 @@ function createStaticMiddleware(options) {
87
101
  }
88
102
  const hit = staticPathRegExp.test(pathname);
89
103
  if (hit) {
90
- const filepath = path.join(pwd, pathname.replace(prefix, () => ""));
104
+ const filepath = path.join(pwd, pathname.replace(pathPrefix, () => ""));
91
105
  if (!await fs.pathExists(filepath)) {
92
106
  return next();
93
107
  }
@@ -18,7 +18,7 @@ async function ssrRender(request, { routeInfo, html, config: userConfig, staticG
18
18
  }
19
19
  const renderBundle = (_serverManifest_renderBundles = serverManifest.renderBundles) === null || _serverManifest_renderBundles === void 0 ? void 0 : _serverManifest_renderBundles[entryName || MAIN_ENTRY_NAME];
20
20
  if (!renderBundle) {
21
- throw new Error(`Can't found renderBundle ${entryName || MAIN_ENTRY_NAME}`);
21
+ throw new Error(`Can't find renderBundle ${entryName || MAIN_ENTRY_NAME}`);
22
22
  }
23
23
  const requestHandler = await renderBundle[SERVER_RUNTIME_ENTRY];
24
24
  const config = createRequestHandlerConfig(userConfig);
@@ -1,6 +1,6 @@
1
1
  import type { AsyncHook, AsyncPipelineHook, ServerContext as BaseServerContext, ServerPlugin as BaseServerPlugin, ServerPluginExtends as BaseServerPluginExtends } from '@modern-js/plugin-v2';
2
2
  import type { Hooks } from '@modern-js/plugin-v2/server';
3
- import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, ISAppContext, UnstableMiddleware } from '@modern-js/types';
3
+ import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, UnstableMiddleware } from '@modern-js/types';
4
4
  import type { MiddlewareHandler } from 'hono';
5
5
  import type { MiddlewareObj } from './base';
6
6
  import type { APIServerStartInput, FallbackInput, ServerConfig, WebAdapter, WebServerStartInput } from './base';
@@ -14,11 +14,7 @@ export interface ServerPluginExtends extends BaseServerPluginExtends {
14
14
  config: ServerConfig;
15
15
  extendContext: {
16
16
  middlewares: MiddlewareObj[];
17
- };
18
- extendApi: {
19
- setAppContext: (c: ISAppContext) => void;
20
- useAppContext: () => ISAppContext;
21
- useConfigContext: () => ServerConfig;
17
+ renderMiddlewares: MiddlewareObj[];
22
18
  };
23
19
  extendHooks: {
24
20
  prepareWebServer: AsyncPipelineHook<PrepareWebServerFn>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.67.4",
18
+ "version": "2.67.6",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -46,7 +46,7 @@
46
46
  "node": ">=16.2.0"
47
47
  },
48
48
  "dependencies": {
49
- "@swc/helpers": "0.5.13",
49
+ "@swc/helpers": "^0.5.17",
50
50
  "@web-std/fetch": "^4.2.1",
51
51
  "@web-std/file": "^3.0.3",
52
52
  "@web-std/stream": "^1.0.3",
@@ -54,10 +54,10 @@
54
54
  "flatted": "^3.2.9",
55
55
  "hono": "^3.12.2",
56
56
  "ts-deepmerge": "7.0.2",
57
- "@modern-js/plugin": "2.67.4",
58
- "@modern-js/plugin-v2": "2.67.4",
59
- "@modern-js/runtime-utils": "2.67.4",
60
- "@modern-js/utils": "2.67.4"
57
+ "@modern-js/plugin": "2.67.6",
58
+ "@modern-js/plugin-v2": "2.67.6",
59
+ "@modern-js/runtime-utils": "2.67.6",
60
+ "@modern-js/utils": "2.67.6"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/cloneable-readable": "^2.0.3",
@@ -68,7 +68,7 @@
68
68
  "jest": "^29",
69
69
  "ts-jest": "^29.1.0",
70
70
  "typescript": "^5",
71
- "@modern-js/types": "2.67.4",
71
+ "@modern-js/types": "2.67.6",
72
72
  "@scripts/build": "2.66.0",
73
73
  "@scripts/jest-config": "2.66.0"
74
74
  },