XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

improve: use express.static to serve webui (#225)

6dd5ceab
Sainan <sainan@calamity.gg>
提交于

代码差异

1 个文件 +8 -10
Modified src/routes/webui.ts +8 -10
@@ -3,22 +3,20 @@ import path from "path";
3 3
4 4 const webuiRouter = express.Router();
5 5
6 // Redirect / to /webui/
6 7 webuiRouter.get("/", (_req, res) => {
7 8 res.redirect("/webui/");
8 9 });
9 10
10 const rootDir = path.join(__dirname, "../..");
11
12 webuiRouter.get("/webui/", (req, res) => {
13 if (req.path != "/webui/") {
14 res.redirect("/webui/");
15 } else {
16 res.sendFile(path.join(rootDir, "static/webui/index.html"));
11 // Redirect /webui to /webui/
12 webuiRouter.use("/webui", (req, res, next) => {
13 if (req.originalUrl === "/") {
14 return res.redirect("/webui/");
17 15 }
16 next();
18 17 });
19 18
20 webuiRouter.get("/webui/script.js", (_req, res) => {
21 res.sendFile(path.join(rootDir, "static/webui/script.js"));
22 });
19 // Serve static files from the webui directory
20 webuiRouter.use("/webui", express.static(path.join(__dirname, "../..", "static/webui")));
23 21
24 22 export { webuiRouter };