From 058d5f3c3fe2d0e6e74f45b0929c897c578818b3 Mon Sep 17 00:00:00 2001 From: Patrick McElhaney Date: Tue, 11 Oct 2022 17:41:09 -0400 Subject: [PATCH] move the landing / dashboard page to an external HTML file --- src/client/index.html | 43 ++++++++++++++++++++++++++++++++++++++ src/server/start.js | 44 ++++++++------------------------------- test/server/start.test.js | 4 ++-- 3 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 src/client/index.html diff --git a/src/client/index.html b/src/client/index.html new file mode 100644 index 00000000..1d922c6f --- /dev/null +++ b/src/client/index.html @@ -0,0 +1,43 @@ + + + + Counterfact + + + + + +

Counterfact is running!

+ + + diff --git a/src/server/start.js b/src/server/start.js index 97eaeef1..dbe451b5 100644 --- a/src/server/start.js +++ b/src/server/start.js @@ -9,6 +9,9 @@ import { readFile } from "../util/read-file.js"; import { counterfact } from "./counterfact.js"; +// eslint-disable-next-line no-underscore-dangle +const __dirname = nodePath.dirname(new URL(import.meta.url).pathname); + const DEFAULT_PORT = 3100; function swaggerUi(app, openApiPath, port) { @@ -44,46 +47,17 @@ function swaggerUi(app, openApiPath, port) { ); } -export function landingPageBody(basePath) { - return ` - - - Counterfact - - - -

Counterfact is running!

- - - -`; +export async function landingPageBody(basePath) { + const body = await readFile(nodePath.join(__dirname, "../client/index.html")); + + return body.replaceAll("{{basePath}}", basePath); } export function landingPage(app, basePath) { app.use(async (ctx, next) => { if (ctx.URL.pathname === "/counterfact") { - ctx.body = landingPageBody(basePath); + // eslint-disable-next-line require-atomic-updates + ctx.body = await landingPageBody(basePath); return; } diff --git a/test/server/start.test.js b/test/server/start.test.js index f7139c24..6760f4e3 100644 --- a/test/server/start.test.js +++ b/test/server/start.test.js @@ -1,9 +1,9 @@ import { landingPageBody } from "../../src/server/start.js"; describe("start", () => { - it("renders the landing page", () => { + it("renders the landing page", async () => { const basePath = "/home/user/counterfact"; - const result = landingPageBody(basePath); + const result = await landingPageBody(basePath); expect(result).toContain(basePath); });