summaryrefslogtreecommitdiff
path: root/server/mod.ts
blob: 1d168d2c3071a73260720bdd4b4d318481abe931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-run

export * from "./ci.ts";
export * from "./health.ts";
export * from "./job.ts";

import { CiHookServer } from "./mod.ts";
import { Either, type IEither } from "@emprespresso/pengueno";
const server = new CiHookServer();

export const runServer = (
  port: number,
  host: string,
): Promise<IEither<Error, 0>> => {
  const serverConfig = {
    host,
    port,
  };
  return Either.fromFailable<Error, Deno.HttpServer>(() =>
    Deno.serve(serverConfig, (req) => server.serve(req)),
  ).flatMapAsync((server) => Either.fromFailableAsync(() => server.finished.then(() => 0)));
};