From 92e6e4404e92fb604effc98110111db1b42482b6 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sat, 17 Apr 2021 10:38:45 +0200 Subject: Add version.txt endpoint --- index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'index.ts') 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 { } } -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) }); } -- cgit v1.3