diff options
Diffstat (limited to 'server/index.ts')
-rw-r--r-- | server/index.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/index.ts b/server/index.ts new file mode 100644 index 0000000..c33b43e --- /dev/null +++ b/server/index.ts @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +export * from './job'; +export * from './ci'; +export * from './health'; + +import { CiHookServer } from '.'; +import { Either, type IEither } from '@emprespresso/pengueno'; +import { serve } from '@hono/node-server'; +import { Hono } from 'hono'; + +const server = new CiHookServer(); + +const neverEndingPromise = new Promise<IEither<Error, 0>>(() => {}); +export const runServer = (port: number, host: string): Promise<IEither<Error, 0>> => + Either.fromFailable<Error, void>(() => { + const app = new Hono(); + + app.all('*', async (c) => { + const response = await server.serve(c.req.raw); + return response; + }); + + serve({ + fetch: app.fetch, + port, + hostname: host, + }); + + console.log(`server running on http://${host}:${port} :D`); + }).flatMapAsync(() => neverEndingPromise); |