From 166606fa8d21b016a15174e89ac27b4c2ddcfe8f Mon Sep 17 00:00:00 2001 From: holmityd Date: Tue, 9 Jan 2024 14:28:06 +0400 Subject: [PATCH] file path handling in route to use absolute path --- src/index.ts | 7 ++++--- src/routes/cache.ts | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 450a5be5..a4be668a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,18 +3,19 @@ import https from "https"; import fs from "node:fs"; import { app } from "./app"; import { logger } from "./utils/logger"; +import { join } from "path"; //const morgan = require("morgan"); //const bodyParser = require("body-parser"); const options = { - key: fs.readFileSync("static/certs/key.pem"), - cert: fs.readFileSync("static/certs/cert.pem"), + key: fs.readFileSync(join(__dirname, "../static/certs/key.pem")), + cert: fs.readFileSync(join(__dirname, "../static/certs/cert.pem")), passphrase: "123456" }; // const server = http.createServer(app).listen(80); http.createServer(app).listen(80, () => logger.info("cache server started on port 80")); -const server = https.createServer(options, app).listen(443, () => logger.info("game server started on port 443")); +https.createServer(options, app).listen(443, () => logger.info("game server started on port 443")); // server.keepAliveTimeout = 60 * 1000 + 1000; // server.headersTimeout = 60 * 1000 + 2000; diff --git a/src/routes/cache.ts b/src/routes/cache.ts index dba00602..5844465a 100644 --- a/src/routes/cache.ts +++ b/src/routes/cache.ts @@ -1,18 +1,19 @@ import express from "express"; import config from "@/config.json"; +import { join } from "path"; const cacheRouter = express.Router(); cacheRouter.get("/B.Cache.Dx11.bin.*", (_req, res) => { - res.sendFile("static/data/B.Cache.Dx11_33.0.6.bin", { root: "./" }); + res.sendFile(join(__dirname, "../../static/data/B.Cache.Dx11_33.0.6.bin")); }); cacheRouter.get("/B.Cache.Windows_en.bin*", (_req, res) => { - res.sendFile("static/data/B.Cache.Windows_en_33.0.10.bin", { root: "./" }); + res.sendFile(join(__dirname, "../../static/data/B.Cache.Windows_en_33.0.10.bin")); }); cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => { - res.sendFile(`static/data/H.Cache_${config.version}.bin`, { root: "./" }); + res.sendFile(join(__dirname, `../../static/data/H.Cache_${config.version}.bin`)); }); export { cacheRouter };