Add public health endpoint for Docker healthcheck
This commit is contained in:
+1
-1
@@ -27,6 +27,6 @@ USER spooty
|
|||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
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"]
|
CMD ["node", "backend/main.js"]
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ import { Controller, Get } from '@nestjs/common';
|
|||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor() {}
|
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getHello(): string {
|
getHello(): string {
|
||||||
return 'ONLINE';
|
return 'ONLINE';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('health')
|
||||||
|
getHealth(): { status: string } {
|
||||||
|
return { status: 'ok' };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ import type { Request } from 'express';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
canActivate(context: ExecutionContext): boolean {
|
canActivate(context: ExecutionContext): boolean {
|
||||||
|
const request = context.switchToHttp().getRequest<Request>();
|
||||||
|
|
||||||
|
if (request.path === '/api/health') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.authEnabled()) {
|
if (!this.authEnabled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -20,7 +26,6 @@ export class AuthGuard implements CanActivate {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = context.switchToHttp().getRequest<Request>();
|
|
||||||
const providedToken = this.extractToken(request);
|
const providedToken = this.extractToken(request);
|
||||||
|
|
||||||
if (providedToken !== expectedToken) {
|
if (providedToken !== expectedToken) {
|
||||||
|
|||||||
Reference in New Issue
Block a user