From fd2013a7bf4129b05080f01ef199d69b9ef9ec68 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Mon, 27 Apr 2020 18:17:06 -0400 Subject: Refactor startup to passthrough values Even more refactoring - however there were some small troubles using path in the nested scripts/files, so referencing them via the index should be a bit more stable. Plus, the config unit tests won't just exit because of configOrError constants strewn about the file. --- src/routes.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/routes.ts') diff --git a/src/routes.ts b/src/routes.ts index 7ebb610..98260fa 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -17,7 +17,7 @@ const HOST_DIR = configOrError("HOST_DIR"); const logger = winston.createLogger(loggerConfig("HTTP")); -export default (metadata: Metadata): Router => { +export default (metadata: Metadata, publicPath: string): Router => { const router = Router(); // serve landing page @@ -33,15 +33,12 @@ export default (metadata: Metadata): Router => { }) ); - // serve static files // favicon should be served directly on root router.get("/favicon.ico", (_, res) => { - res.sendFile(path.join(__dirname, "..", "public", "static", "favicon.ico")); + res.sendFile(path.join(publicPath, "static", "favicon.ico")); }); - router.use( - "/static", - express.static(path.join(__dirname, "..", "public", "static")) - ); + // serve static files + router.use("/static", express.static(path.join(publicPath, "static"))); // Upload HTML file router.post("/v1/:org/:repo/:branch/:commit.html", (req, res) => { @@ -219,7 +216,7 @@ export default (metadata: Metadata): Router => { router.use((_, res) => { res.status(404); - res.sendFile(path.join(__dirname, "..", "public", "static", "404.html")); + res.sendFile(path.join(publicPath, "static", "404.html")); }); return router; -- cgit