Skip to content

Commit 9e760ea

Browse files
committed
fix: disable cache on config route
ref: #35 Signed-off-by: A. Ottr <alex@otter.foo>
1 parent 3937339 commit 9e760ea

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

backend/src/config/config.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import { ConfigDTO } from "./dto/config.dto";
2222
import { TestEmailDTO } from "./dto/testEmail.dto";
2323
import UpdateConfigDTO from "./dto/updateConfig.dto";
2424
import { LogoService } from "./logo.service";
25+
import { NoCacheInterceptor } from "./interceptor/no-cache.interceptor";
2526

2627
@Controller("configs")
28+
@UseInterceptors(NoCacheInterceptor)
2729
export class ConfigController {
2830
constructor(
2931
private configService: ConfigService,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
CallHandler,
3+
ExecutionContext,
4+
Injectable,
5+
NestInterceptor,
6+
} from "@nestjs/common";
7+
import { Observable } from "rxjs";
8+
import { tap } from "rxjs/operators";
9+
10+
@Injectable()
11+
export class NoCacheInterceptor implements NestInterceptor {
12+
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
13+
const response = context.switchToHttp().getResponse();
14+
15+
return next.handle().pipe(
16+
tap(() => {
17+
// Set headers to prevent caching by reverse proxies
18+
response.setHeader(
19+
"Cache-Control",
20+
"no-store, no-cache, must-revalidate, private",
21+
);
22+
response.setHeader("Pragma", "no-cache");
23+
response.setHeader("Expires", "0");
24+
}),
25+
);
26+
}
27+
}
28+

0 commit comments

Comments
 (0)