feat: add reverse proxy support and port configuration

main
borja (aider) 3 months ago
parent 084af2018e
commit 0245ef15e9

@ -25,9 +25,16 @@ type WebhookPayload = {
}; };
export class WebhookServer { 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<Response> { static async handleRequest(request: Request): Promise<Response> {
// Health check endpoint // 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 }); return new Response('OK', { status: 200 });
} }
@ -115,8 +122,7 @@ export class WebhookServer {
static async start() { static async start() {
this.validateEnv(); this.validateEnv();
// const PORT = process.env.PORT || '3007'; const PORT = process.env.PORT || '3007';
const PORT = '80';
console.log('✅ Environment variables validated'); console.log('✅ Environment variables validated');
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {

@ -43,7 +43,13 @@ export class WebhookManager {
try { try {
const url = new URL(process.env.WEBHOOK_URL); 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'); throw new Error('WEBHOOK_URL must use http or https protocol');
} }
} catch (e) { } catch (e) {

Loading…
Cancel
Save