Add public health endpoint for Docker healthcheck

This commit is contained in:
Tor Matz Andrén
2026-05-14 17:17:51 +02:00
parent 33f077ed1e
commit abc63c0cec
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -27,6 +27,6 @@ USER spooty
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD curl -fsS http://127.0.0.1:3000/api || exit 1
CMD curl -fsS http://127.0.0.1:3000/api/health || exit 1
CMD ["node", "backend/main.js"]
+5 -2
View File
@@ -2,10 +2,13 @@ import { Controller, Get } from '@nestjs/common';
@Controller()
export class AppController {
constructor() {}
@Get()
getHello(): string {
return 'ONLINE';
}
@Get('health')
getHealth(): { status: string } {
return { status: 'ok' };
}
}
+6 -1
View File
@@ -9,6 +9,12 @@ import type { Request } from 'express';
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest<Request>();
if (request.path === '/api/health') {
return true;
}
if (!this.authEnabled()) {
return true;
}
@@ -20,7 +26,6 @@ export class AuthGuard implements CanActivate {
);
}
const request = context.switchToHttp().getRequest<Request>();
const providedToken = this.extractToken(request);
if (providedToken !== expectedToken) {