@modern-js/server-core 2.67.5 → 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 =
|
|
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(
|
|
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
|
}
|
|
@@ -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 =
|
|
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(
|
|
170
|
+
filepath = path.join(pwd, pathname.replace(pathPrefix, function() {
|
|
157
171
|
return "";
|
|
158
172
|
}));
|
|
159
173
|
return [
|
|
@@ -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 =
|
|
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(
|
|
104
|
+
const filepath = path.join(pwd, pathname.replace(pathPrefix, () => ""));
|
|
91
105
|
if (!await fs.pathExists(filepath)) {
|
|
92
106
|
return next();
|
|
93
107
|
}
|
|
@@ -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,
|
|
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.
|
|
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",
|
|
@@ -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.
|
|
58
|
-
"@modern-js/plugin-v2": "2.67.
|
|
59
|
-
"@modern-js/runtime-utils": "2.67.
|
|
60
|
-
"@modern-js/utils": "2.67.
|
|
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,9 +68,9 @@
|
|
|
68
68
|
"jest": "^29",
|
|
69
69
|
"ts-jest": "^29.1.0",
|
|
70
70
|
"typescript": "^5",
|
|
71
|
-
"@modern-js/types": "2.67.
|
|
72
|
-
"@scripts/
|
|
73
|
-
"@scripts/
|
|
71
|
+
"@modern-js/types": "2.67.6",
|
|
72
|
+
"@scripts/build": "2.66.0",
|
|
73
|
+
"@scripts/jest-config": "2.66.0"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
76
|
"publishConfig": {
|