summaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-08-17 23:50:24 -0700
committerElizabeth Hunt <me@liz.coffee>2025-08-17 23:53:38 -0700
commit1a4fc9535a89b58e8b67c8996ade0b833116af3a (patch)
treed16f3129d7bb69f204bba8422e909354195a0042 /index.ts
parent157dc327e8fe63541b517cfbeeaf202a3e8553a5 (diff)
downloaduptime-1a4fc9535a89b58e8b67c8996ade0b833116af3a.tar.gz
uptime-1a4fc9535a89b58e8b67c8996ade0b833116af3a.zip
Move to pengueno.
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts36
1 files changed, 34 insertions, 2 deletions
diff --git a/index.ts b/index.ts
index a352aee..557898c 100644
--- a/index.ts
+++ b/index.ts
@@ -1,3 +1,35 @@
-import { main } from "./src/api";
+#!/usr/bin/env node
-main(parseInt(process.env.PORT ?? "3000"));
+import { argv, IEither, Either } from '@emprespresso/pengueno';
+import { runServer } from '@emprespresso/uptime';
+
+const main = (_argv = process.argv.slice(2)): Promise<IEither<Error, void>> =>
+ argv(
+ ['--run-server', '--port', '--host'],
+ {
+ '--run-server': { absent: false, unspecified: true, present: () => true },
+ '--port': { absent: 9000, present: (port) => parseInt(port) },
+ '--host': { absent: '0.0.0.0', present: (host) => host },
+ },
+ _argv,
+ )
+ .mapRight((args) => ({
+ server_mode: args['--run-server'],
+ port: args['--port'],
+ host: args['--host'],
+ }))
+ .flatMapAsync(async (runConfig) => {
+ if (!runConfig.server_mode) {
+ return Either.right(<void>undefined);
+ }
+ return runServer(runConfig.port, runConfig.host);
+ });
+
+if (process.argv[1] === import.meta.filename) {
+ await main().then((eitherDone) =>
+ eitherDone.mapLeft((err) => {
+ console.error('error:', err);
+ process.exit(1);
+ }),
+ );
+}