import { FourOhFourActivityImpl, getEnv, HealthCheckActivityImpl, type HealthChecker, type IFourOhFourActivity, type IHealthCheckActivity, type ITraceable, PenguenoRequest, Server, type ServerTrace, } from '@emprespresso/pengueno'; import type { Job } from '@emprespresso/ci_model'; import { healthCheck as _healthCheck, type IJobHookActivity, type IJobQueuer, JobHookActivityImpl, LaminarJobQueuer, } from '@emprespresso/ci_server'; export const DEFAULT_CI_SERVER = 'https://ci.liz.coffee'; export class CiHookServer implements Server { constructor( healthCheck: HealthChecker = _healthCheck, jobQueuer: IJobQueuer> = new LaminarJobQueuer( getEnv('LAMINAR_URL') .orSome(() => DEFAULT_CI_SERVER) .get(), ), private readonly healthCheckActivity: IHealthCheckActivity = new HealthCheckActivityImpl(healthCheck), private readonly jobHookActivity: IJobHookActivity = new JobHookActivityImpl(jobQueuer), private readonly fourOhFourActivity: IFourOhFourActivity = new FourOhFourActivityImpl(), ) {} public serve(req: ITraceable) { const url = new URL(req.get().req.url); if (url.pathname === '/health') { return this.healthCheckActivity.checkHealth(req); } if (url.pathname === '/job') { return this.jobHookActivity.processHook(req); } return this.fourOhFourActivity.fourOhFour(req); } }