agent-publish-server 1.0.27 → 1.0.28
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 +2 -0
- package/README_EN.md +3 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.js +15 -5
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,7 @@ interface AgentConfig {
|
|
|
99
99
|
[path: string]: {
|
|
100
100
|
target: string; // 目标URL
|
|
101
101
|
changeOrigin?: boolean; // 更改源头
|
|
102
|
+
ws?: boolean; // 启用 WebSocket 代理
|
|
102
103
|
pathRewrite?: {
|
|
103
104
|
// 路径重写规则
|
|
104
105
|
[pattern: string]: string;
|
|
@@ -273,6 +274,7 @@ agent-publish-server --log false
|
|
|
273
274
|
|
|
274
275
|
### 版本历史
|
|
275
276
|
|
|
277
|
+
- **v1.0.28**: 新增 proxy.ws 配置,支持 WebSocket upgrade 代理转发
|
|
276
278
|
- **v1.0.27**: 新增404兜底重定向配置(fallbackRedirect),当路由匹配不上时自动重定向到指定路径,避免黑屏或404错误
|
|
277
279
|
- **v1.0.26**: 新增根路径重定向配置(redirect),支持访问 / 时自动跳转到指定路径
|
|
278
280
|
- **v1.0.25**: 修复 staticProxy static 类型不支持 SPA History 路由刷新的问题,添加自动 fallback 到 index.html 支持
|
package/README_EN.md
CHANGED
|
@@ -106,6 +106,7 @@ With this config, accessing `http://localhost:3000/` will redirect to `http://lo
|
|
|
106
106
|
interface ProxyConfig {
|
|
107
107
|
target: string; // Target server URL
|
|
108
108
|
changeOrigin?: boolean; // Change origin header
|
|
109
|
+
ws?: boolean; // Enable WebSocket proxy
|
|
109
110
|
pathRewrite?: Record<string, string>; // Path rewriting rules
|
|
110
111
|
}
|
|
111
112
|
```
|
|
@@ -249,6 +250,8 @@ startServer(app, config.port);
|
|
|
249
250
|
|
|
250
251
|
## Version History
|
|
251
252
|
|
|
253
|
+
- **v1.0.28**: Added proxy.ws configuration to support WebSocket upgrade proxy forwarding
|
|
254
|
+
- **v1.0.27**: Added 404 fallback redirect configuration (fallbackRedirect), automatically redirects unmatched routes to the specified path
|
|
252
255
|
- **v1.0.26**: Added root path redirect configuration (redirect), supports automatic redirect when accessing /
|
|
253
256
|
- **v1.0.25**: Fixed staticProxy static type not supporting SPA History route refresh, added automatic fallback to index.html
|
|
254
257
|
- **v1.0.24**: Fixed mobile compatibility issues, optimized HTTP response headers for consistent iOS and Android display
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
1
2
|
import { AgentConfig } from "./types";
|
|
2
|
-
|
|
3
|
+
type ProxyMiddleware = ReturnType<typeof createProxyMiddleware>;
|
|
4
|
+
export declare function createServer(config: AgentConfig, wsProxyMiddlewares?: ProxyMiddleware[]): import("express-serve-static-core").Express;
|
|
3
5
|
export declare function startServer(config: AgentConfig): Promise<void>;
|
|
6
|
+
export {};
|
package/dist/server.js
CHANGED
|
@@ -9,7 +9,7 @@ const express_1 = __importDefault(require("express"));
|
|
|
9
9
|
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const fs_1 = __importDefault(require("fs"));
|
|
12
|
-
function createServer(config) {
|
|
12
|
+
function createServer(config, wsProxyMiddlewares = []) {
|
|
13
13
|
const app = (0, express_1.default)();
|
|
14
14
|
const staticDir = config.dir || "./";
|
|
15
15
|
const enableLog = config.log !== false; // 默认为true
|
|
@@ -41,8 +41,12 @@ function createServer(config) {
|
|
|
41
41
|
}
|
|
42
42
|
// 配置API代理
|
|
43
43
|
if (config.proxy) {
|
|
44
|
-
Object.entries(config.proxy).forEach(([
|
|
45
|
-
|
|
44
|
+
Object.entries(config.proxy).forEach(([proxyPath, proxyConfig]) => {
|
|
45
|
+
const proxyMiddleware = (0, http_proxy_middleware_1.createProxyMiddleware)(proxyPath, proxyConfig);
|
|
46
|
+
app.use(proxyMiddleware);
|
|
47
|
+
if (proxyConfig.ws === true) {
|
|
48
|
+
wsProxyMiddlewares.push(proxyMiddleware);
|
|
49
|
+
}
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
// 配置静态网页代理
|
|
@@ -201,14 +205,20 @@ function createServer(config) {
|
|
|
201
205
|
}
|
|
202
206
|
function startServer(config) {
|
|
203
207
|
try {
|
|
204
|
-
const
|
|
208
|
+
const wsProxyMiddlewares = [];
|
|
209
|
+
const app = createServer(config, wsProxyMiddlewares);
|
|
205
210
|
const port = config.port || 8080;
|
|
206
211
|
return new Promise((resolve, reject) => {
|
|
207
212
|
try {
|
|
208
|
-
app.listen(port, () => {
|
|
213
|
+
const server = app.listen(port, () => {
|
|
209
214
|
console.log(`Server is running at http://localhost:${port}`);
|
|
210
215
|
resolve();
|
|
211
216
|
});
|
|
217
|
+
wsProxyMiddlewares.forEach((proxyMiddleware) => {
|
|
218
|
+
if (proxyMiddleware.upgrade) {
|
|
219
|
+
server.on("upgrade", proxyMiddleware.upgrade);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
212
222
|
}
|
|
213
223
|
catch (error) {
|
|
214
224
|
console.error("Failed to start server:", error);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-publish-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "A powerful frontend development server with API proxy, static file serving, and dual-mode static proxy support. Built with Node.js + Express + http-proxy-middleware. 基于 Node.js + Express + http-proxy-middleware 的强大前端开发服务器,支持API代理、静态文件服务和双模式静态代理。",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|