feat: 优化静态资源缓存策略
This commit is contained in:
@@ -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(开发文档)
|
||||
|
||||
Reference in New Issue
Block a user