From b74bcd5dd227f67da00202c7c5384350ab5fac09 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 22 Sep 2022 10:18:50 -0400 Subject: [PATCH] *Add newRouter function that defines a root endpoint and returns the pubkey *Call newRouter in resetRouter *Call resetRouter in start --- src/modules/app.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 7a67192..aa65152 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -2,6 +2,7 @@ import express, { Express } from "express"; import http from "http"; import { AddressInfo } from "net"; import log from "loglevel"; +import { getKeyPair } from "./dht"; let app: Express; let router = express.Router(); @@ -18,6 +19,7 @@ export function setRouter(newRouter: express.Router): void { export async function start() { app = express(); server = http.createServer(app); + resetRouter(); await new Promise((resolve) => { server.listen(80, "0.0.0.0", function () { const address = server.address() as AddressInfo; @@ -42,5 +44,17 @@ export function getServer(): http.Server { } export function resetRouter(): void { - setRouter(express.Router()); + setRouter(newRouter()); +} + +function newRouter(): express.Router { + const router = express.Router(); + + let keyPair = getKeyPair(); + + router.get("/", (req, res) => { + res.send(Buffer.from(keyPair.publicKey).toString("hex")); + }); + + return router; }