feat: healthcheck
This commit is contained in:
parent
db3ac97813
commit
305f91c6bd
@ -25,15 +25,33 @@ spec:
|
||||
- name: handy
|
||||
image: docker.korshakov.com/handy-server:{version}
|
||||
ports:
|
||||
- containerPort: 3001
|
||||
- containerPort: 3005
|
||||
env:
|
||||
- name: NODE_ENV
|
||||
value: production
|
||||
- name: PORT
|
||||
value: "3005"
|
||||
- name: REDIS_URL
|
||||
value: redis://happy-redis:6379
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: handy-secrets
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 3005
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 3005
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
|
@ -64,7 +64,7 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
|
||||
logger: true,
|
||||
bodyLimit: 1024 * 1024 * 100, // 100MB
|
||||
});
|
||||
app.register(require('@fastify/cors'), {
|
||||
app.register(import('@fastify/cors'), {
|
||||
origin: '*',
|
||||
allowedHeaders: '*',
|
||||
methods: ['GET', 'POST']
|
||||
@ -72,6 +72,27 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
|
||||
app.get('/', function (request, reply) {
|
||||
reply.send('Welcome to Happy Server!');
|
||||
});
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/health', async (request, reply) => {
|
||||
try {
|
||||
// Test database connectivity
|
||||
await db.$queryRaw`SELECT 1`;
|
||||
reply.send({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
service: 'happy-server'
|
||||
});
|
||||
} catch (error) {
|
||||
log({ module: 'health', level: 'error' }, `Health check failed: ${error}`);
|
||||
reply.code(503).send({
|
||||
status: 'error',
|
||||
timestamp: new Date().toISOString(),
|
||||
service: 'happy-server',
|
||||
error: 'Database connectivity failed'
|
||||
});
|
||||
}
|
||||
});
|
||||
app.setValidatorCompiler(validatorCompiler);
|
||||
app.setSerializerCompiler(serializerCompiler);
|
||||
const typed = app.withTypeProvider<ZodTypeProvider>();
|
||||
|
Loading…
Reference in New Issue
Block a user