fix: correct server class structure and improve error handling

main
borja (aider) 3 months ago
parent 352d201db5
commit 2b4d95d3ab

@ -1,4 +1,10 @@
import { WebhookServer } from './src/server'; import { WebhookServer } from './src/server';
console.log("Starting WhatsApp Task Bot..."); console.log("Starting WhatsApp Task Bot...");
WebhookServer.start(); try {
WebhookServer.start();
console.log("Server started successfully");
} catch (error) {
console.error("Failed to start server:", error);
process.exit(1);
}

@ -71,13 +71,13 @@ export class WebhookServer {
} }
} }
static start() { static start() {
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
const server = Bun.serve({ const server = Bun.serve({
port: PORT, port: PORT,
fetch: WebhookServer.handleRequest, fetch: WebhookServer.handleRequest,
}); });
console.log(`Server running on port ${PORT}`); console.log(`Server running on port ${PORT}`);
return server; return server;
}
} }
}

@ -5,7 +5,11 @@ describe('WebhookServer', () => {
const envBackup = process.env; const envBackup = process.env;
beforeEach(() => { beforeEach(() => {
process.env = { ...envBackup, INSTANCE_NAME: 'test-instance' }; process.env = {
...envBackup,
INSTANCE_NAME: 'test-instance',
NODE_ENV: 'test'
};
}); });
afterEach(() => { afterEach(() => {

Loading…
Cancel
Save