From edc3186d6487aa922e4df3afec4075887d58b0c1 Mon Sep 17 00:00:00 2001 From: Caramel Date: Tue, 28 Nov 2023 19:49:57 +0100 Subject: [PATCH] Add cache --- backend/src/app.module.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 91c5f93..12fd58c 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -37,6 +37,17 @@ const imageCorsOverride = ( next(); }; +const imageCacheSet = ( + req: IncomingMessage, + res: ServerResponse, + next: () => void, +) => { + // Set cache for a month + res.setHeader('Cache-Control', 'max-age=2592000'); + + next(); +}; + @Module({ imports: [ PicsurLoggerModule, @@ -56,6 +67,8 @@ const imageCorsOverride = ( export class AppModule implements NestModule { configure(consumer: MiddlewareConsumer) { consumer.apply(mainCorsConfig).exclude('i/(.*)').forRoutes('*'); - consumer.apply(imageCorsConfig, imageCorsOverride).forRoutes('i/(.*)'); + consumer + .apply(imageCorsConfig, imageCorsOverride, imageCacheSet) + .forRoutes('i/(.*)'); } }