[DevOps] Add /health endpoint and Docker HEALTHCHECK
- src/routes/health/+server.ts: lightweight health endpoint returning 200 OK - Dockerfile: HEALTHCHECK hitting /health every 30s, 5s timeout, 10s start period Enables Docker/Nginx zero-downtime routing and auto-recovery.
This commit is contained in:
@@ -43,4 +43,8 @@ COPY --from=builder /app/.env.production .env
|
|||||||
# SvelteKit (via adapter-node) defaults to port 3000.
|
# SvelteKit (via adapter-node) defaults to port 3000.
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Healthcheck to verify the app is running
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
|
CMD node -e "fetch('http://localhost:3000/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"
|
||||||
|
|
||||||
CMD ["node", "index.js"]
|
CMD ["node", "index.js"]
|
||||||
|
|||||||
19
src/routes/health/+server.ts
Normal file
19
src/routes/health/+server.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Health Check Endpoint
|
||||||
|
* Used by Docker and Nginx to verify the service is running.
|
||||||
|
*/
|
||||||
|
export const GET: RequestHandler = async () => {
|
||||||
|
return json({
|
||||||
|
status: 'healthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
service: 'aether-app-sveltekit',
|
||||||
|
node_env: process.env.NODE_ENV || 'development'
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user