Skip to content

Commit

Permalink
Add cache
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Nov 28, 2023
1 parent acca12f commit edc3186
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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/(.*)');
}
}

0 comments on commit edc3186

Please sign in to comment.