diff --git a/src/server.ts b/src/server.ts index ed21281..7baea59 100644 --- a/src/server.ts +++ b/src/server.ts @@ -25,9 +25,16 @@ type WebhookPayload = { }; export class WebhookServer { + private static getBaseUrl(request: Request): string { + const proto = request.headers.get('x-forwarded-proto') || 'http'; + const host = request.headers.get('x-forwarded-host') || request.headers.get('host'); + return `${proto}://${host}`; + } + static async handleRequest(request: Request): Promise { // Health check endpoint - if (request.url.endsWith('/health')) { + const url = new URL(request.url); + if (url.pathname.endsWith('/health')) { return new Response('OK', { status: 200 }); } @@ -115,8 +122,7 @@ export class WebhookServer { static async start() { this.validateEnv(); - // const PORT = process.env.PORT || '3007'; - const PORT = '80'; + const PORT = process.env.PORT || '3007'; console.log('✅ Environment variables validated'); if (process.env.NODE_ENV !== 'test') { diff --git a/src/services/webhook-manager.ts b/src/services/webhook-manager.ts index 90603dd..2654c06 100644 --- a/src/services/webhook-manager.ts +++ b/src/services/webhook-manager.ts @@ -43,7 +43,13 @@ export class WebhookManager { try { const url = new URL(process.env.WEBHOOK_URL); - if (!['http:', 'https:'].includes(url.protocol)) { + // Allow internal docker URLs in production + if (process.env.NODE_ENV === 'production') { + if (!['http:', 'https:', 'http://srv-captain--'].some(prefix => + process.env.WEBHOOK_URL?.startsWith(prefix))) { + console.warn('Production WEBHOOK_URL should use http/https or internal docker URL'); + } + } else if (!['http:', 'https:'].includes(url.protocol)) { throw new Error('WEBHOOK_URL must use http or https protocol'); } } catch (e) {