Skip to content

Commit

Permalink
🚀 Add API Health for Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdra committed Oct 12, 2024
1 parent cad4964 commit 983e6df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.caddy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -36,6 +43,7 @@ services:
networks:
- app-network-caddy


networks:
app-network-caddy:
driver: bridge
Expand Down

0 comments on commit 983e6df

Please sign in to comment.