aboutsummaryrefslogtreecommitdiffstats
path: root/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/index.ts b/index.ts
index a3bb69c..5bf62c7 100644
--- a/index.ts
+++ b/index.ts
@@ -1,4 +1,4 @@
-import { serve } from "https://deno.land/std@0.93.0/http/server.ts";
+import { serve } from "https://deno.land/std/http/server.ts";
import "https://deno.land/x/dotenv/load.ts";
const SERVER_PORT = Deno.env.get("SERVER_PORT") ?? "8080";
const SERVER_HOST = Deno.env.get("SERVER_HOST") ?? "localhost";
@@ -59,11 +59,19 @@ async function getRepositories(): Promise<Repository[] | undefined> {
}
}
-const s = serve({ port: parseInt(SERVER_PORT), hostname: SERVER_HOST });
-console.log("http://"+SERVER_HOST+":" + SERVER_PORT);
-for await (const req of s) {
+console.log("srht-git-feed is running on: http://" + SERVER_HOST + ":" + SERVER_PORT);
+for await (const req of serve({ port: parseInt(SERVER_PORT), hostname: SERVER_HOST })) {
try {
- req.respond({ body: JSON.stringify(await getRepositories()) });
+ if (req.url === "/version.txt") {
+ req.respond({ body: await Deno.readTextFile("version.txt") });
+ } else if (req.url === "/") {
+ req.respond({ body: JSON.stringify(await getRepositories()) });
+ } else {
+ req.respond({
+ status: 404
+ });
+ }
+
} catch(err) {
req.respond({ body: JSON.stringify(err) });
}