diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-04-17 10:38:45 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-04-17 10:38:45 +0200 |
| commit | 92e6e4404e92fb604effc98110111db1b42482b6 (patch) | |
| tree | ce59fc69bc2c771d8728d1f15d38e2ab8a167107 /index.ts | |
| parent | 0cbaa868f894e01fe97e091c49b6c140b5c66561 (diff) | |
| download | srht-git-feed-92e6e4404e92fb604effc98110111db1b42482b6.tar.xz srht-git-feed-92e6e4404e92fb604effc98110111db1b42482b6.zip | |
Add version.txt endpoint
Diffstat (limited to 'index.ts')
| -rw-r--r-- | index.ts | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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) }); } |
