agent-publish-server 1.0.25 → 1.0.26
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 +21 -0
- package/README_EN.md +21 -0
- package/dist/server.js +9 -0
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ agent-publish-server -c ./agent_config.json
|
|
|
91
91
|
interface AgentConfig {
|
|
92
92
|
port?: number; // 服务器端口(默认:8080)
|
|
93
93
|
dir?: string; // 静态文件目录(默认:"./")
|
|
94
|
+
redirect?: string; // 根路径重定向,如 "/app" 表示访问 / 时重定向到 /app
|
|
94
95
|
log?: boolean; // 启用访问日志(默认:true)
|
|
95
96
|
proxy?: {
|
|
96
97
|
// API代理配置
|
|
@@ -114,6 +115,25 @@ interface AgentConfig {
|
|
|
114
115
|
}
|
|
115
116
|
```
|
|
116
117
|
|
|
118
|
+
### 根路径重定向
|
|
119
|
+
|
|
120
|
+
通过 `redirect` 配置实现访问根路径时自动重定向到指定路径:
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"port": 3000,
|
|
125
|
+
"redirect": "/app",
|
|
126
|
+
"staticProxy": {
|
|
127
|
+
"/app": {
|
|
128
|
+
"target": "./dist",
|
|
129
|
+
"type": "static"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
这样配置后,访问 `http://localhost:3000/` 会自动重定向到 `http://localhost:3000/app`。
|
|
136
|
+
|
|
117
137
|
### 静态网页代理
|
|
118
138
|
|
|
119
139
|
除了 API 代理外,还支持静态网页代理功能,用于代理整个网站或应用。
|
|
@@ -228,6 +248,7 @@ agent-publish-server --log false
|
|
|
228
248
|
|
|
229
249
|
### 版本历史
|
|
230
250
|
|
|
251
|
+
- **v1.0.26**: 新增根路径重定向配置(redirect),支持访问 / 时自动跳转到指定路径
|
|
231
252
|
- **v1.0.25**: 修复 staticProxy static 类型不支持 SPA History 路由刷新的问题,添加自动 fallback 到 index.html 支持
|
|
232
253
|
- **v1.0.24**: 修复移动端兼容性问题,优化 HTTP 响应头设置,确保 iOS 和 Android 显示一致性
|
|
233
254
|
- **v1.0.23**: 完善双语文档支持,优化 package.json 关键词,提升 npm 包曝光度
|
package/README_EN.md
CHANGED
|
@@ -77,9 +77,29 @@ agent-publish-server -c config.json
|
|
|
77
77
|
|
|
78
78
|
- **port**: Server port (default: 3000)
|
|
79
79
|
- **dir**: Static file directory (default: current directory)
|
|
80
|
+
- **redirect**: Root path redirect, e.g. "/app" redirects / to /app
|
|
80
81
|
- **proxy**: API proxy configuration
|
|
81
82
|
- **staticProxy**: Static proxy configuration
|
|
82
83
|
|
|
84
|
+
### Root Path Redirect
|
|
85
|
+
|
|
86
|
+
Use `redirect` to automatically redirect root path to a specified path:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"port": 3000,
|
|
91
|
+
"redirect": "/app",
|
|
92
|
+
"staticProxy": {
|
|
93
|
+
"/app": {
|
|
94
|
+
"target": "./dist",
|
|
95
|
+
"type": "static"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
With this config, accessing `http://localhost:3000/` will redirect to `http://localhost:3000/app`.
|
|
102
|
+
|
|
83
103
|
#### API Proxy Configuration (ProxyConfig)
|
|
84
104
|
|
|
85
105
|
```typescript
|
|
@@ -229,6 +249,7 @@ startServer(app, config.port);
|
|
|
229
249
|
|
|
230
250
|
## Version History
|
|
231
251
|
|
|
252
|
+
- **v1.0.26**: Added root path redirect configuration (redirect), supports automatic redirect when accessing /
|
|
232
253
|
- **v1.0.25**: Fixed staticProxy static type not supporting SPA History route refresh, added automatic fallback to index.html
|
|
233
254
|
- **v1.0.24**: Fixed mobile compatibility issues, optimized HTTP response headers for consistent iOS and Android display
|
|
234
255
|
- **v1.0.23**: Enhanced bilingual documentation support, optimized package.json keywords for better npm exposure
|
package/dist/server.js
CHANGED
|
@@ -30,6 +30,15 @@ function createServer(config) {
|
|
|
30
30
|
next();
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
+
// 根路径重定向配置
|
|
34
|
+
if (config.redirect) {
|
|
35
|
+
app.get("/", (req, res) => {
|
|
36
|
+
const redirectPath = config.redirect.startsWith("/")
|
|
37
|
+
? config.redirect
|
|
38
|
+
: `/${config.redirect}`;
|
|
39
|
+
res.redirect(302, redirectPath);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
33
42
|
// 配置API代理
|
|
34
43
|
if (config.proxy) {
|
|
35
44
|
Object.entries(config.proxy).forEach(([path, proxyConfig]) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ export interface ProxyConfig {
|
|
|
5
5
|
}
|
|
6
6
|
export interface StaticProxyConfig {
|
|
7
7
|
target: string;
|
|
8
|
-
type?:
|
|
8
|
+
type?: "http" | "static";
|
|
9
9
|
changeOrigin?: boolean;
|
|
10
10
|
}
|
|
11
11
|
export interface AgentConfig {
|
|
12
12
|
port?: number;
|
|
13
13
|
dir?: string;
|
|
14
|
+
redirect?: string;
|
|
14
15
|
proxy?: Record<string, ProxyConfig>;
|
|
15
16
|
staticProxy?: Record<string, StaticProxyConfig>;
|
|
16
17
|
log?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-publish-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
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",
|