agent-publish-server 1.0.19 → 1.0.22
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/README.md +40 -12
- package/dist/server.js +20 -7
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/test-static-proxy.json +5 -0
package/README.md
CHANGED
|
@@ -250,8 +250,9 @@ interface AgentConfig {
|
|
|
250
250
|
staticProxy?: {
|
|
251
251
|
// 静态网页代理配置
|
|
252
252
|
[path: string]: {
|
|
253
|
-
target: string; // 目标URL
|
|
254
|
-
|
|
253
|
+
target: string; // 目标URL或本地文件路径
|
|
254
|
+
type?: "http" | "static"; // 代理类型(默认:http)
|
|
255
|
+
changeOrigin?: boolean; // 更改源头,仅http类型有效(默认:true)
|
|
255
256
|
};
|
|
256
257
|
};
|
|
257
258
|
}
|
|
@@ -259,15 +260,31 @@ interface AgentConfig {
|
|
|
259
260
|
|
|
260
261
|
### 静态网页代理
|
|
261
262
|
|
|
262
|
-
除了API代理外,还支持静态网页代理功能,用于代理整个网站或应用。
|
|
263
|
+
除了 API 代理外,还支持静态网页代理功能,用于代理整个网站或应用。
|
|
263
264
|
|
|
264
265
|
#### 配置示例
|
|
265
266
|
|
|
267
|
+
**静态文件代理:**
|
|
268
|
+
|
|
266
269
|
```json
|
|
267
270
|
{
|
|
268
271
|
"staticProxy": {
|
|
269
272
|
"/sub_page": {
|
|
273
|
+
"target": "./dist",
|
|
274
|
+
"type": "static"
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**HTTP 服务代理:**
|
|
281
|
+
|
|
282
|
+
```json
|
|
283
|
+
{
|
|
284
|
+
"staticProxy": {
|
|
285
|
+
"/app": {
|
|
270
286
|
"target": "http://localhost:3000",
|
|
287
|
+
"type": "http",
|
|
271
288
|
"changeOrigin": true
|
|
272
289
|
}
|
|
273
290
|
}
|
|
@@ -276,12 +293,14 @@ interface AgentConfig {
|
|
|
276
293
|
|
|
277
294
|
#### 功能特性
|
|
278
295
|
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
-
|
|
282
|
-
-
|
|
296
|
+
- **双重代理模式**:支持静态文件代理和 HTTP 服务代理
|
|
297
|
+
- **静态文件代理**:直接代理到本地文件系统目录
|
|
298
|
+
- **HTTP 服务代理**:代理到远程 HTTP 服务,支持路径重写
|
|
299
|
+
- **自动路径处理**:自动处理代理路径前缀
|
|
300
|
+
- **优先级处理**:静态代理优先于默认静态文件服务
|
|
301
|
+
- **路径验证**:自动检查静态文件路径是否存在
|
|
283
302
|
|
|
284
|
-
#### 与API代理组合使用
|
|
303
|
+
#### 与 API 代理组合使用
|
|
285
304
|
|
|
286
305
|
`staticProxy` 可以与 `proxy` 配置同时使用:
|
|
287
306
|
|
|
@@ -295,8 +314,13 @@ interface AgentConfig {
|
|
|
295
314
|
}
|
|
296
315
|
},
|
|
297
316
|
"staticProxy": {
|
|
298
|
-
"/
|
|
317
|
+
"/dist_files": {
|
|
318
|
+
"target": "./dist",
|
|
319
|
+
"type": "static"
|
|
320
|
+
},
|
|
321
|
+
"/remote_app": {
|
|
299
322
|
"target": "http://localhost:3001",
|
|
323
|
+
"type": "http",
|
|
300
324
|
"changeOrigin": true
|
|
301
325
|
}
|
|
302
326
|
}
|
|
@@ -304,9 +328,11 @@ interface AgentConfig {
|
|
|
304
328
|
```
|
|
305
329
|
|
|
306
330
|
这样配置后:
|
|
307
|
-
|
|
308
|
-
- 访问 `/
|
|
309
|
-
-
|
|
331
|
+
|
|
332
|
+
- 访问 `/api/*` 会代理到 `http://localhost:3000/*`(API 服务)
|
|
333
|
+
- 访问 `/dist_files/*` 会访问本地 `./dist` 目录下的静态文件
|
|
334
|
+
- 访问 `/remote_app/*` 会代理到 `http://localhost:3001/*`(远程应用)
|
|
335
|
+
- 其他路径会访问默认静态文件目录
|
|
310
336
|
|
|
311
337
|
### 访问日志
|
|
312
338
|
|
|
@@ -346,6 +372,8 @@ agent-publish-server --log false
|
|
|
346
372
|
|
|
347
373
|
### 版本历史
|
|
348
374
|
|
|
375
|
+
- **v1.0.22**: 优化和完善staticProxy功能,提升稳定性
|
|
376
|
+
- **v1.0.18**: 增强staticProxy功能,支持静态文件代理和HTTP服务代理两种模式
|
|
349
377
|
- **v1.0.17**: 新增静态网页代理功能(staticProxy),支持与API代理同时使用
|
|
350
378
|
- **v1.0.16**: 新增交互式配置、访问日志、路径验证功能
|
|
351
379
|
- **v1.0.15**: 基础代理和静态文件服务功能
|
package/dist/server.js
CHANGED
|
@@ -38,14 +38,27 @@ function createServer(config) {
|
|
|
38
38
|
}
|
|
39
39
|
// 配置静态网页代理
|
|
40
40
|
if (config.staticProxy) {
|
|
41
|
-
Object.entries(config.staticProxy).forEach(([
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
Object.entries(config.staticProxy).forEach(([proxyPath, staticProxyConfig]) => {
|
|
42
|
+
const proxyType = staticProxyConfig.type || 'http'; // 默认为http类型
|
|
43
|
+
if (proxyType === 'static') {
|
|
44
|
+
// 静态文件代理
|
|
45
|
+
const staticPath = path_1.default.resolve(process.cwd(), staticProxyConfig.target);
|
|
46
|
+
if (!fs_1.default.existsSync(staticPath)) {
|
|
47
|
+
console.warn(`Warning: Static proxy path does not exist: ${staticPath}`);
|
|
48
|
+
return;
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
app.use(proxyPath, express_1.default.static(staticPath));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// HTTP服务代理
|
|
54
|
+
app.use(proxyPath, (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
55
|
+
target: staticProxyConfig.target,
|
|
56
|
+
changeOrigin: staticProxyConfig.changeOrigin !== false, // 默认为true
|
|
57
|
+
pathRewrite: {
|
|
58
|
+
[`^${proxyPath}`]: '' // 移除代理路径前缀
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
49
62
|
});
|
|
50
63
|
}
|
|
51
64
|
// 配置静态文件服务
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED