diff --git a/gateway/HTTPServer.ts b/gateway/HTTPServer.ts deleted file mode 100644 index 07f1d4d..0000000 --- a/gateway/HTTPServer.ts +++ /dev/null @@ -1,9 +0,0 @@ -import express from "express" - -const HTTP_PORT = process.env.HTTP_PORT || 3000 - -export const httpServer = express() - -httpServer.listen(HTTP_PORT, () => { - console.info("HTTP server tunning on http://localhost:" + HTTP_PORT) -}) diff --git a/gateway/index.ts b/gateway/index.ts index 9fe45d9..3e0b728 100644 --- a/gateway/index.ts +++ b/gateway/index.ts @@ -1,15 +1,19 @@ import { config } from "dotenv-flow" config() import readConfig from "./Config" -import { httpServer } from "./HTTPServer" import getMetrics from "./MetricsGenerator" import setupMQTTClient from "./MQTTClient" +import { routerBuilder, setupServer } from "useful-typescript-functions" async function setup() { const config = await readConfig() setupMQTTClient(config) - httpServer.get("/metrics", async (req, res) => { - res.header("Content-Type", "text/plain").send(getMetrics(config)) + setupServer({ + middlewares: [ + routerBuilder("/metrics", "metrics") + .get("/", (req) => getMetrics(config)) + .build(), + ], }) } diff --git a/test.http b/test.http new file mode 100644 index 0000000..59fceb3 --- /dev/null +++ b/test.http @@ -0,0 +1 @@ +GET http://localhost:8080/metrics