env-plugin 0.5.7 → 0.5.8
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/client/assets/{element-plus-wndYbaZY.js.gz → element-plus-ketO_xfq.js.gz} +0 -0
- package/dist/client/assets/{index-nrcddKJg.css.gz → index-Crqzm-vz.css.gz} +0 -0
- package/dist/client/assets/index-D9lpgDpN.js.gz +0 -0
- package/dist/client/index.html +3 -3
- package/dist/service/PreProxyServer.js +6 -21
- package/dist/service/RouteRuleService.js +4 -4
- package/dist/types/shared/RouteRule.js +0 -5
- package/package.json +1 -1
- package/dist/client/assets/index-Bl3B2M1W.js.gz +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/client/index.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<link rel="icon" href="/favicon.ico" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>ENVM (环境管理)</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-D9lpgDpN.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/vue-BGFZjnqd.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/element-plus-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/element-plus-ketO_xfq.js">
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Crqzm-vz.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="app"></div>
|
|
@@ -83,21 +83,6 @@ class PreProxyServer {
|
|
|
83
83
|
static get configCookieSuffix() {
|
|
84
84
|
return `${getConfig().cookieSuffix}`;
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
* 根据请求路径匹配路由规则,检查是否需要注入 Script
|
|
88
|
-
* @param requestPath 请求路径
|
|
89
|
-
* @returns 是否需要注入 Script
|
|
90
|
-
*/
|
|
91
|
-
shouldInjectScript(requestPath) {
|
|
92
|
-
const routeRules = this.routeRuleRepo.getByEnvId(this.envId);
|
|
93
|
-
const enabledRules = routeRules.filter((rule) => rule.enabled !== false);
|
|
94
|
-
for (const rule of enabledRules) {
|
|
95
|
-
if (minimatch(requestPath, rule.pathPrefix, { dot: true })) {
|
|
96
|
-
return rule.injectScript === true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
86
|
/**
|
|
102
87
|
* 根据请求路径匹配路由规则
|
|
103
88
|
* @param requestPath 请求路径
|
|
@@ -211,9 +196,8 @@ class PreProxyServer {
|
|
|
211
196
|
proxyReq.setHeader("cookie", newCookies.join(";"));
|
|
212
197
|
}
|
|
213
198
|
}
|
|
214
|
-
_rewriteLoginRedirect(proxyRes,
|
|
199
|
+
_rewriteLoginRedirect(proxyRes, _req, res) {
|
|
215
200
|
const contentType = proxyRes.headers["content-type"] || "";
|
|
216
|
-
const requestPath = req.path || "/";
|
|
217
201
|
// 转发状态码 + 响应头
|
|
218
202
|
res.statusCode = proxyRes.statusCode || 200;
|
|
219
203
|
for (const key in proxyRes.headers) {
|
|
@@ -226,13 +210,11 @@ class PreProxyServer {
|
|
|
226
210
|
proxyRes.on("end", () => {
|
|
227
211
|
try {
|
|
228
212
|
const body = Buffer.concat(chunks);
|
|
229
|
-
// 只对 HTML
|
|
230
|
-
if (contentType.includes("text/html")
|
|
231
|
-
this.shouldInjectScript(requestPath)) {
|
|
213
|
+
// 只对 HTML 且配置了注入脚本目录
|
|
214
|
+
if (contentType.includes("text/html")) {
|
|
232
215
|
const config = getConfig();
|
|
233
216
|
const scriptDir = config.injectScriptDir;
|
|
234
217
|
if (!scriptDir) {
|
|
235
|
-
devServerLogger.warn("未配置注入脚本目录 (injectScriptDir)");
|
|
236
218
|
res.end(body);
|
|
237
219
|
return;
|
|
238
220
|
}
|
|
@@ -261,6 +243,9 @@ class PreProxyServer {
|
|
|
261
243
|
* @returns 脚本标签 HTML
|
|
262
244
|
*/
|
|
263
245
|
generateImportScripts(scriptDir) {
|
|
246
|
+
if (!scriptDir) {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
264
249
|
const fullPath = path.resolve(scriptDir);
|
|
265
250
|
if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isDirectory()) {
|
|
266
251
|
devServerLogger.warn(`注入脚本目录不存在: ${fullPath}`);
|
|
@@ -42,16 +42,16 @@ class RouteRuleService {
|
|
|
42
42
|
* @throws {Error} 当输入参数不合法或目标环境不存在时抛出
|
|
43
43
|
*/
|
|
44
44
|
handleAdd(routeRuleItem) {
|
|
45
|
-
const { envId, pathPrefix, targetEnvId
|
|
46
|
-
//
|
|
45
|
+
const { envId, pathPrefix, targetEnvId } = routeRuleItem;
|
|
46
|
+
// 检查目标环境是否存在
|
|
47
47
|
if (targetEnvId) {
|
|
48
48
|
const targetEnv = this.envRepo.findOneById(targetEnvId);
|
|
49
49
|
if (!targetEnv) {
|
|
50
50
|
throw new Error(`添加失败,目标环境【${targetEnvId}】不存在`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// 目标环境不能为空
|
|
54
|
+
if (!targetEnvId) {
|
|
55
55
|
throw new Error("添加失败,目标环境不能为空");
|
|
56
56
|
}
|
|
57
57
|
// 检查是否已存在相同路径前缀的规则(同一环境下)
|
|
@@ -20,11 +20,6 @@ export const RouteRuleBaseSchema = z.object({
|
|
|
20
20
|
.describe("目标环境ID(转发到此环境)"),
|
|
21
21
|
description: z.string().optional().describe("描述"),
|
|
22
22
|
enabled: z.boolean().optional().default(true).describe("是否启用"),
|
|
23
|
-
injectScript: z
|
|
24
|
-
.boolean()
|
|
25
|
-
.optional()
|
|
26
|
-
.default(false)
|
|
27
|
-
.describe("是否注入Script脚本"),
|
|
28
23
|
createdAt: z.string().optional(),
|
|
29
24
|
updatedAt: z.string().optional(),
|
|
30
25
|
});
|
package/package.json
CHANGED
|
Binary file
|