refactor: Some path refactoring
This commit is contained in:
11
server.ts
11
server.ts
@@ -20,6 +20,9 @@ import { getCurrentInterval } from "./scheduleRules.js";
|
||||
import bodyParser from "body-parser";
|
||||
import cors from "cors";
|
||||
|
||||
const DB_FOLDER = path.join(process.cwd(), "volume", "db");
|
||||
const WEB_FOLDER = path.join(process.cwd(), "web", "public");
|
||||
|
||||
const VERSIONS = ["v1", "v2", "v3"];
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
@@ -39,9 +42,9 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
const isBrowser = /Mozilla|Chrome|Firefox|Safari|Edg/.test(userAgent);
|
||||
|
||||
if (isBrowser) {
|
||||
res.sendFile(path.join(process.cwd(), "web", "public", "index.html"));
|
||||
res.sendFile(path.join(WEB_FOLDER, "index.html"));
|
||||
} else {
|
||||
const dataStr = await fs.readFile(path.join(process.cwd(), "db", "v1.json"), "utf8");
|
||||
const dataStr = await fs.readFile(path.join(DB_FOLDER, "v1.json"), "utf8");
|
||||
const data = JSON.parse(dataStr);
|
||||
|
||||
data["status"]["currentUpdateSchedule"] = getCurrentInterval();
|
||||
@@ -51,7 +54,7 @@ app.get('/', async (req: Request, res: Response) => {
|
||||
});
|
||||
|
||||
app.get('/versioned/v1', async (_: Request, res: Response) => {
|
||||
const dataStr = await fs.readFile(path.join(process.cwd(), "db", "v1.json"), "utf8");
|
||||
const dataStr = await fs.readFile(path.join(DB_FOLDER, "v1.json"), "utf8");
|
||||
const data = JSON.parse(dataStr);
|
||||
|
||||
data["status"]["currentUpdateSchedule"] = getCurrentInterval();
|
||||
@@ -62,7 +65,7 @@ app.get('/versioned/v1', async (_: Request, res: Response) => {
|
||||
VERSIONS.forEach((version) => {
|
||||
app.get(`/versioned/${version}`, async (_: Request, res: Response) => {
|
||||
try {
|
||||
const filePath = path.join(process.cwd(), "db", `${version}.json`);
|
||||
const filePath = path.join(DB_FOLDER, `${version}.json`);
|
||||
const dataStr = await fs.readFile(filePath, "utf8");
|
||||
const data = JSON.parse(dataStr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user