autosnippet 2.19.5 → 2.19.7
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/lib/http/HttpServer.js +18 -5
- package/package.json +1 -1
package/lib/http/HttpServer.js
CHANGED
|
@@ -123,8 +123,21 @@ export class HttpServer {
|
|
|
123
123
|
this.app.use(this.performanceMonitor.middleware());
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
//
|
|
127
|
-
this.app.use(helmet(
|
|
126
|
+
// 安全头(放宽 CSP 以兼容 Vite 构建的 Dashboard SPA:script/style 需要内联和 crossorigin)
|
|
127
|
+
this.app.use(helmet({
|
|
128
|
+
contentSecurityPolicy: {
|
|
129
|
+
directives: {
|
|
130
|
+
defaultSrc: ["'self'"],
|
|
131
|
+
scriptSrc: ["'self'", "'unsafe-inline'"],
|
|
132
|
+
styleSrc: ["'self'", "'unsafe-inline'", "https:"],
|
|
133
|
+
imgSrc: ["'self'", "data:", "blob:"],
|
|
134
|
+
connectSrc: ["'self'", "ws:", "wss:"],
|
|
135
|
+
fontSrc: ["'self'", "https:", "data:"],
|
|
136
|
+
objectSrc: ["'none'"],
|
|
137
|
+
frameSrc: ["'none'"],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
128
141
|
|
|
129
142
|
// 请求日志
|
|
130
143
|
this.app.use(requestLogger(this.logger));
|
|
@@ -268,13 +281,13 @@ export class HttpServer {
|
|
|
268
281
|
});
|
|
269
282
|
});
|
|
270
283
|
|
|
271
|
-
// 404
|
|
272
|
-
this.app.
|
|
284
|
+
// 404 处理(使用 app.all 确保 layer.route 存在,mountDashboard 依赖此属性定位并重排路由栈)
|
|
285
|
+
this.app.all('*', (req, res) => {
|
|
273
286
|
res.status(404).json({
|
|
274
287
|
success: false,
|
|
275
288
|
error: {
|
|
276
289
|
code: 'NOT_FOUND',
|
|
277
|
-
message: `Route not found: ${req.method} ${req.
|
|
290
|
+
message: `Route not found: ${req.method} ${req.originalUrl}`,
|
|
278
291
|
},
|
|
279
292
|
});
|
|
280
293
|
});
|