diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-08-17 23:50:24 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-08-17 23:53:38 -0700 |
commit | 1a4fc9535a89b58e8b67c8996ade0b833116af3a (patch) | |
tree | d16f3129d7bb69f204bba8422e909354195a0042 /lib/server.ts | |
parent | 157dc327e8fe63541b517cfbeeaf202a3e8553a5 (diff) | |
download | uptime-1a4fc9535a89b58e8b67c8996ade0b833116af3a.tar.gz uptime-1a4fc9535a89b58e8b67c8996ade0b833116af3a.zip |
Move to pengueno.
Diffstat (limited to 'lib/server.ts')
-rw-r--r-- | lib/server.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/server.ts b/lib/server.ts new file mode 100644 index 0000000..9885bf3 --- /dev/null +++ b/lib/server.ts @@ -0,0 +1,35 @@ +import { + FourOhFourActivityImpl, + HealthCheckActivityImpl, + type HealthChecker, + type IFourOhFourActivity, + type IHealthCheckActivity, + type ITraceable, + PenguenoRequest, + Server, + type ServerTrace, +} from '@emprespresso/pengueno'; +import { healthCheck as _healthCheck, EmailActivityImpl, IEmailActivity, Inbox, Outbox } from './index'; + +export class UptimeServer implements Server { + constructor( + healthCheck: HealthChecker = _healthCheck, + private readonly healthCheckActivity: IHealthCheckActivity = new HealthCheckActivityImpl(healthCheck), + private readonly emailActivity: IEmailActivity = new EmailActivityImpl( + (a) => Outbox.from(a), + (b) => Inbox.from(b), + ), + private readonly fourOhFourActivity: IFourOhFourActivity = new FourOhFourActivityImpl(), + ) {} + + public serve(req: ITraceable<PenguenoRequest, ServerTrace>) { + const url = new URL(req.get().req.url); + if (url.pathname === '/health') { + return this.healthCheckActivity.checkHealth(req); + } + if (url.pathname === '/email') { + return this.emailActivity.runMail(req); + } + return this.fourOhFourActivity.fourOhFour(req); + } +} |