fix: deployment issues and add health check

main
borja (aider) 3 months ago
parent 2e40bd8522
commit 027e11523e

@ -1,16 +1,21 @@
# Use official Bun image for optimal performance # Use official Bun image with Alpine for smaller size
FROM oven/bun:1.1 as base FROM oven/bun:1.1-alpine as base
WORKDIR /app WORKDIR /app
# Install dependencies first (better layer caching) # Install dependencies first (better layer caching)
COPY package.json ./ COPY package.json bun.lock ./
RUN bun install RUN bun install --production
# Copy all source files # Copy only necessary files
COPY . . COPY src/ ./src/
COPY index.ts ./
# Server runs on port 3007 by default (override with PORT env var) # Health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:3007/health || exit 1
# Server runs on port 3007 by default
EXPOSE 3007 EXPOSE 3007
# Start the server (env vars will be injected by CapRover) # Start the server
CMD ["bun", "run", "index.ts"] CMD ["bun", "run", "index.ts"]

@ -4,8 +4,9 @@ console.log("Starting WhatsApp Task Bot...");
try { try {
const server = WebhookServer.start(); const server = WebhookServer.start();
console.log("Server started successfully"); console.log("Server started successfully");
export default server;
} catch (error) { } catch (error) {
console.error("Failed to start server:", error); console.error("Failed to start server:", error);
process.exit(1); process.exit(1);
} }
export default WebhookServer;

@ -24,6 +24,11 @@ type WebhookPayload = {
export class WebhookServer { export class WebhookServer {
static async handleRequest(request: Request): Promise<Response> { static async handleRequest(request: Request): Promise<Response> {
// Health check endpoint
if (request.url.endsWith('/health')) {
return new Response('OK', { status: 200 });
}
// 1. Method validation // 1. Method validation
if (request.method !== 'POST') { if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 }); return new Response('Method not allowed', { status: 405 });

Loading…
Cancel
Save