mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
39 lines
975 B
TypeScript
39 lines
975 B
TypeScript
import { ApplicationError } from 'n8n-workflow';
|
|
import { createServer } from 'node:http';
|
|
|
|
export class HealthcheckServer {
|
|
private server = createServer((_, res) => {
|
|
res.writeHead(200);
|
|
res.end('OK');
|
|
});
|
|
|
|
async start(host: string, port: number) {
|
|
return await new Promise<void>((resolve, reject) => {
|
|
const portInUseErrorHandler = (error: NodeJS.ErrnoException) => {
|
|
if (error.code === 'EADDRINUSE') {
|
|
reject(new ApplicationError(`Port ${port} is already in use`));
|
|
} else {
|
|
reject(error);
|
|
}
|
|
};
|
|
|
|
this.server.on('error', portInUseErrorHandler);
|
|
|
|
this.server.listen(port, host, () => {
|
|
this.server.removeListener('error', portInUseErrorHandler);
|
|
console.log(`Healthcheck server listening on ${host}, port ${port}`);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
async stop() {
|
|
return await new Promise<void>((resolve, reject) => {
|
|
this.server.close((error) => {
|
|
if (error) reject(error);
|
|
else resolve();
|
|
});
|
|
});
|
|
}
|
|
}
|