From 32a2590a3471eb8d52a3a7e96c2c14b9493d2d0a Mon Sep 17 00:00:00 2001 From: Griffin Quarles Date: Thu, 24 Oct 2024 19:01:58 -0400 Subject: [PATCH] Add /html endpoint to serve HTML files Add a new endpoint `/html/:name` to serve HTML files from the `uploads` directory. * Use `res.sendFile` to serve the HTML file. * Construct the file path using `path.join`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gquarles/quickhost?shareId=XXXX-XXXX-XXXX-XXXX). --- server.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server.js b/server.js index 7c01ce7..d7a4469 100644 --- a/server.js +++ b/server.js @@ -44,6 +44,12 @@ app.get("/files/:name", function (req, res) { res.download(path.join(__dirname, `/uploads/${fileName}`)); }); +app.get("/html/:name", function (req, res) { + let fileName = req.params.name; + + res.sendFile(path.join(__dirname, `/uploads/${fileName}`)); +}); + app.post("/upload", upload.single("file"), (req, res) => { return res.status(200).send(req.file); });