Add public health endpoint for Docker healthcheck
This commit is contained in:
+1
-1
@@ -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"]
|
||||
|
||||
@@ -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' };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user