agent-publish-server 1.0.23 → 1.0.24

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 CHANGED
@@ -228,6 +228,7 @@ agent-publish-server --log false
228
228
 
229
229
  ### 版本历史
230
230
 
231
+ - **v1.0.24**: 修复移动端兼容性问题,优化HTTP响应头设置,确保iOS和Android显示一致性
231
232
  - **v1.0.23**: 完善双语文档支持,优化package.json关键词,提升npm包曝光度
232
233
  - **v1.0.22**: 优化和完善 staticProxy 功能,提升稳定性
233
234
  - **v1.0.18**: 增强 staticProxy 功能,支持静态文件代理和 HTTP 服务代理两种模式
package/README_EN.md CHANGED
@@ -229,6 +229,8 @@ startServer(app, config.port);
229
229
 
230
230
  ## Version History
231
231
 
232
+ - **v1.0.24**: Fixed mobile compatibility issues, optimized HTTP response headers for consistent iOS and Android display
233
+ - **v1.0.23**: Enhanced bilingual documentation support, optimized package.json keywords for better npm exposure
232
234
  - **v1.0.22**: Optimized and improved staticProxy functionality, enhanced stability
233
235
  - **v1.0.18**: Enhanced staticProxy functionality, supporting both static file proxy and HTTP service proxy modes
234
236
  - **v1.0.17**: Added static web proxy functionality (staticProxy), supports simultaneous use with API proxy
package/dist/server.js CHANGED
@@ -47,7 +47,33 @@ function createServer(config) {
47
47
  console.warn(`Warning: Static proxy path does not exist: ${staticPath}`);
48
48
  return;
49
49
  }
50
- app.use(proxyPath, express_1.default.static(staticPath));
50
+ app.use(proxyPath, express_1.default.static(staticPath, {
51
+ setHeaders: (res, filePath, stat) => {
52
+ // 设置通用响应头,提升移动端兼容性
53
+ res.setHeader('X-Content-Type-Options', 'nosniff');
54
+ res.setHeader('X-Frame-Options', 'SAMEORIGIN');
55
+ res.setHeader('X-XSS-Protection', '1; mode=block');
56
+ // 针对HTML文件设置移动端优化响应头
57
+ if (filePath.endsWith('.html')) {
58
+ res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
59
+ res.setHeader('Pragma', 'no-cache');
60
+ res.setHeader('Expires', '0');
61
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
62
+ }
63
+ // 针对CSS文件确保正确的Content-Type
64
+ if (filePath.endsWith('.css')) {
65
+ res.setHeader('Content-Type', 'text/css; charset=utf-8');
66
+ }
67
+ // 针对JS文件确保正确的Content-Type
68
+ if (filePath.endsWith('.js')) {
69
+ res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
70
+ }
71
+ // 针对图片文件设置适当的缓存
72
+ if (filePath.match(/\.(jpg|jpeg|png|gif|webp|svg)$/i)) {
73
+ res.setHeader('Cache-Control', 'public, max-age=31536000');
74
+ }
75
+ }
76
+ }));
51
77
  }
52
78
  else {
53
79
  // HTTP服务代理
@@ -61,8 +87,46 @@ function createServer(config) {
61
87
  }
62
88
  });
63
89
  }
64
- // 配置静态文件服务
65
- app.use(express_1.default.static(staticDir));
90
+ // 配置静态文件服务,添加移动端兼容性响应头
91
+ app.use(express_1.default.static(staticDir, {
92
+ setHeaders: (res, filePath, stat) => {
93
+ // 设置通用响应头,提升移动端兼容性
94
+ res.setHeader('X-Content-Type-Options', 'nosniff');
95
+ res.setHeader('X-Frame-Options', 'SAMEORIGIN');
96
+ res.setHeader('X-XSS-Protection', '1; mode=block');
97
+ // 针对HTML文件设置移动端优化响应头
98
+ if (filePath.endsWith('.html')) {
99
+ res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
100
+ res.setHeader('Pragma', 'no-cache');
101
+ res.setHeader('Expires', '0');
102
+ // 确保正确的Content-Type
103
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
104
+ }
105
+ // 针对CSS文件确保正确的Content-Type
106
+ if (filePath.endsWith('.css')) {
107
+ res.setHeader('Content-Type', 'text/css; charset=utf-8');
108
+ }
109
+ // 针对JS文件确保正确的Content-Type
110
+ if (filePath.endsWith('.js')) {
111
+ res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
112
+ }
113
+ // 针对图片文件设置适当的缓存
114
+ if (filePath.match(/\.(jpg|jpeg|png|gif|webp|svg)$/i)) {
115
+ res.setHeader('Cache-Control', 'public, max-age=31536000');
116
+ }
117
+ }
118
+ }));
119
+ // 添加移动端兼容性中间件
120
+ app.use((req, res, next) => {
121
+ // 检测移动端User-Agent并设置相应响应头
122
+ const userAgent = req.get('User-Agent') || '';
123
+ const isMobile = /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
124
+ if (isMobile) {
125
+ // 为移动端设置额外的响应头
126
+ res.setHeader('Vary', 'User-Agent');
127
+ }
128
+ next();
129
+ });
66
130
  // 添加SPA应用的回退路由处理
67
131
  // 只有当实际文件不存在时才回退到index.html
68
132
  app.use((req, res, next) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-publish-server",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
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",