feat: 优化静态资源缓存策略

This commit is contained in:
Nixevol
2026-07-05 22:01:48 +08:00
parent cb202825a3
commit 3efc1ecd88
11 changed files with 265 additions and 3 deletions
+8
View File
@@ -10,6 +10,7 @@ import { AppModule } from './app.module';
import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
import { OperationLogInterceptor } from './operation-log/operation-log.interceptor';
import { STATIC_ASSET_CACHE_CONTROL } from './storage/storage.service';
// 让 BigInt 可被 JSON 序列化为字符串,避免精度问题。
(BigInt.prototype as unknown as { toJSON: () => string }).toJSON = function () {
@@ -54,6 +55,13 @@ async function bootstrap(): Promise<void> {
}
app.useStaticAssets(localDir, {
prefix: config.get<string>('storage.publicPrefix') || '/uploads',
etag: true,
lastModified: true,
maxAge: '1y',
immutable: true,
setHeaders: (res) => {
res.setHeader('Cache-Control', STATIC_ASSET_CACHE_CONTROL);
},
});
// Swagger(开发文档)