diff --git a/backend/Dockerfile.prod b/backend/Dockerfile.prod index fbfe7c9d..31e332f3 100644 --- a/backend/Dockerfile.prod +++ b/backend/Dockerfile.prod @@ -16,6 +16,9 @@ COPY . . # Stage 2: Serve the app FROM node:22-alpine3.20 +# Install curl (use RUN instead of CMD) +RUN apk add --no-cache curl + # Set the working directory WORKDIR /app diff --git a/backend/server.js b/backend/server.js index a3733702..5c54895c 100644 --- a/backend/server.js +++ b/backend/server.js @@ -63,6 +63,10 @@ app.get('/', (_req, res) => { res.send('FarmCart API is Running...') }) +app.get('/health', (req, res) => { + res.status(200).json({ status: 'UP' }); +}); + // Define API routes app.use('/api/users', userRoute) app.use('/api/orders', orderRoute) diff --git a/docker-compose.caddy.yml b/docker-compose.caddy.yml index 6237e1df..b7e5063a 100644 --- a/docker-compose.caddy.yml +++ b/docker-compose.caddy.yml @@ -12,6 +12,13 @@ services: deploy: mode: replicated replicas: 2 + healthcheck: + test: ["CMD", "curl", "-f", "api:5002/health"] # Use service name instead of localhost + interval: 30s + timeout: 10s + retries: 3 + start_period: 5s + # ports: # - "5002:5002" # Expose the API on port 5002 for internal communication @@ -36,6 +43,7 @@ services: networks: - app-network-caddy + networks: app-network-caddy: driver: bridge