summaryrefslogtreecommitdiff
path: root/server/index.ts
blob: c33b43e547bd90600347c520d617ccd4518caf1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);