diff --git a/Dockerfile b/Dockerfile index 9ea081d..8a47b31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,21 @@ -# Use official Bun image for optimal performance -FROM oven/bun:1.1 as base +# Use official Bun image with Alpine for smaller size +FROM oven/bun:1.1-alpine as base WORKDIR /app # Install dependencies first (better layer caching) -COPY package.json ./ -RUN bun install +COPY package.json bun.lock ./ +RUN bun install --production -# Copy all source files -COPY . . +# Copy only necessary files +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 -# Start the server (env vars will be injected by CapRover) +# Start the server CMD ["bun", "run", "index.ts"] diff --git a/index.ts b/index.ts index 2202a0e..f92255c 100644 --- a/index.ts +++ b/index.ts @@ -4,8 +4,9 @@ console.log("Starting WhatsApp Task Bot..."); try { const server = WebhookServer.start(); console.log("Server started successfully"); - export default server; } catch (error) { console.error("Failed to start server:", error); process.exit(1); } + +export default WebhookServer; diff --git a/src/server.ts b/src/server.ts index 0deff6b..c4d06c0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -24,6 +24,11 @@ type WebhookPayload = { export class WebhookServer { static async handleRequest(request: Request): Promise { + // Health check endpoint + if (request.url.endsWith('/health')) { + return new Response('OK', { status: 200 }); + } + // 1. Method validation if (request.method !== 'POST') { return new Response('Method not allowed', { status: 405 });