Explorar o código

feat: add HOST_HOMEPAGE env var feature toggle

Sv443 hai 4 meses
pai
achega
4971b2ed8a
Modificáronse 2 ficheiros con 15 adicións e 10 borrados
  1. 3 0
      .env.template
  2. 12 10
      src/routes/index.ts

+ 3 - 0
.env.template

@@ -6,6 +6,9 @@ HTTP_PORT=8074
 # Defaults to 0.0.0.0 (listen on all interfaces)
 HTTP_HOST=
 
+# Defaults to true - whether to serve the documentation page
+HOST_HOMEPAGE=true
+
 # Gotten from creating a client on https://genius.com/api-clients
 GENIUS_ACCESS_TOKEN=
 

+ 12 - 10
src/routes/index.ts

@@ -7,6 +7,8 @@ import { initSearchRoutes } from "@routes/search.js";
 import { initTranslationsRoutes } from "@routes/translations.js";
 import { initAlbumRoutes } from "@routes/album.js";
 
+const hostHomepage = process.env.HOST_HOMEPAGE?.toLowerCase() !== "false";
+
 const routeFuncs: ((router: Router) => unknown)[] = [
   initSearchRoutes,
   initTranslationsRoutes,
@@ -19,18 +21,18 @@ export function initRouter(app: Application) {
   for(const initRoute of routeFuncs)
     initRoute(router);
 
-  // host docs files
-  router.use("/docs", express.static(resolve("./www/.vuepress/dist")));
-
-  // redirect to docs page
-  router.get("/", (_req, res) => redirectToDocs(res));
+  // mount API router at versioned path
+  app.use(`/v${verMajor}`, router);
 
-  // healthcheck
+  // health check
   router.get("/health", (_req, res) => res.status(200).send("Hello, World!"));
 
-  // redirect to docs page
-  app.get("/docs", (_req, res) => redirectToDocs(res));
+  if(hostHomepage) {
+    // host docs files
+    router.use("/docs", express.static(resolve("./www/.vuepress/dist")));
 
-  // mount router
-  app.use(`/v${verMajor}`, router);
+    // redirect to docs page
+    router.get("/", (_req, res) => redirectToDocs(res));
+    app.get("/docs", (_req, res) => redirectToDocs(res));
+  }
 }