improve: use express.static to serve webui (#225)
This commit is contained in:
parent
376b75be39
commit
6dd5ceabde
@ -3,22 +3,20 @@ import path from "path";
|
|||||||
|
|
||||||
const webuiRouter = express.Router();
|
const webuiRouter = express.Router();
|
||||||
|
|
||||||
|
// Redirect / to /webui/
|
||||||
webuiRouter.get("/", (_req, res) => {
|
webuiRouter.get("/", (_req, res) => {
|
||||||
res.redirect("/webui/");
|
res.redirect("/webui/");
|
||||||
});
|
});
|
||||||
|
|
||||||
const rootDir = path.join(__dirname, "../..");
|
// Redirect /webui to /webui/
|
||||||
|
webuiRouter.use("/webui", (req, res, next) => {
|
||||||
webuiRouter.get("/webui/", (req, res) => {
|
if (req.originalUrl === "/") {
|
||||||
if (req.path != "/webui/") {
|
return res.redirect("/webui/");
|
||||||
res.redirect("/webui/");
|
|
||||||
} else {
|
|
||||||
res.sendFile(path.join(rootDir, "static/webui/index.html"));
|
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
webuiRouter.get("/webui/script.js", (_req, res) => {
|
// Serve static files from the webui directory
|
||||||
res.sendFile(path.join(rootDir, "static/webui/script.js"));
|
webuiRouter.use("/webui", express.static(path.join(__dirname, "../..", "static/webui")));
|
||||||
});
|
|
||||||
|
|
||||||
export { webuiRouter };
|
export { webuiRouter };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user