पाठ 23 / 30

Deployment और Production

Best practices के साथ Fastify को production में ले जाएँ।

Production checklist

NODE_ENV=production सेट करें, secrets के लिए environment variables उपयोग करें, health checks जोड़ें, HTTPS enable करें, और reverse proxy उपयोग करें।

Health check endpoint

Load balancers को आपके app को monitor करने के लिए एक simple health check route।

fastify.get('/health', async () => {
  return {
    status: 'ok',
    uptime: process.uptime(),
    timestamp: new Date().toISOString(),
  };
});

fastify.get('/ready', async () => {
  // Check database connectivity, external services, etc.
  try {
    await fastify.db.query('SELECT 1');
    return { ready: true };
  } catch {
    return reply.status(503).send({ ready: false });
  }
});