feat: healthcheck
This commit is contained in:
parent
db3ac97813
commit
305f91c6bd
@ -25,15 +25,33 @@ spec:
|
|||||||
- name: handy
|
- name: handy
|
||||||
image: docker.korshakov.com/handy-server:{version}
|
image: docker.korshakov.com/handy-server:{version}
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 3001
|
- containerPort: 3005
|
||||||
env:
|
env:
|
||||||
- name: NODE_ENV
|
- name: NODE_ENV
|
||||||
value: production
|
value: production
|
||||||
|
- name: PORT
|
||||||
|
value: "3005"
|
||||||
- name: REDIS_URL
|
- name: REDIS_URL
|
||||||
value: redis://happy-redis:6379
|
value: redis://happy-redis:6379
|
||||||
envFrom:
|
envFrom:
|
||||||
- secretRef:
|
- secretRef:
|
||||||
name: handy-secrets
|
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
|
apiVersion: policy/v1
|
||||||
kind: PodDisruptionBudget
|
kind: PodDisruptionBudget
|
||||||
|
@ -64,7 +64,7 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
|
|||||||
logger: true,
|
logger: true,
|
||||||
bodyLimit: 1024 * 1024 * 100, // 100MB
|
bodyLimit: 1024 * 1024 * 100, // 100MB
|
||||||
});
|
});
|
||||||
app.register(require('@fastify/cors'), {
|
app.register(import('@fastify/cors'), {
|
||||||
origin: '*',
|
origin: '*',
|
||||||
allowedHeaders: '*',
|
allowedHeaders: '*',
|
||||||
methods: ['GET', 'POST']
|
methods: ['GET', 'POST']
|
||||||
@ -72,6 +72,27 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
|
|||||||
app.get('/', function (request, reply) {
|
app.get('/', function (request, reply) {
|
||||||
reply.send('Welcome to Happy Server!');
|
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.setValidatorCompiler(validatorCompiler);
|
||||||
app.setSerializerCompiler(serializerCompiler);
|
app.setSerializerCompiler(serializerCompiler);
|
||||||
const typed = app.withTypeProvider<ZodTypeProvider>();
|
const typed = app.withTypeProvider<ZodTypeProvider>();
|
||||||
|
Loading…
Reference in New Issue
Block a user