Skip to content

Commit 8f85833

Browse files
committed
Add cache headers for images controller
1 parent 09a0ecf commit 8f85833

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

apps/api/src/images/images.controller.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { Controller, Get, Param, Redirect, Res } from '@nestjs/common';
1+
import { Controller, Get, Header, Param, Redirect, Res } from '@nestjs/common';
22
import { Response } from 'express';
33
import { ImagesService } from './images.service';
44

5+
const ONE_DAY = 24 * 60 * 60;
6+
const CACHE_TIME = 30 * ONE_DAY;
7+
58
@Controller('images')
69
export class ImagesController {
710
constructor(private readonly imagesService: ImagesService) {}
811

912
@Get('default')
13+
@Header('Cache-Control', `public, max-age=${CACHE_TIME}`)
1014
@Redirect('/public/default.png', 302)
1115
getDefault() {}
1216

1317
@Get(':key')
18+
@Header('Cache-Control', `public, max-age=${CACHE_TIME}`)
1419
async getByKey(@Param('key') key: string, @Res() response: Response) {
1520
const object = await this.imagesService.getObject(key);
1621
object.pipe(response);

0 commit comments

Comments
 (0)