diff --git a/routes/projectsDB.ts b/routes/projectsDB.ts index bb60268..c21b6aa 100644 --- a/routes/projectsDB.ts +++ b/routes/projectsDB.ts @@ -1,7 +1,8 @@ import { Client } from "pg"; import activateDb from "../db"; -import express from "express"; -const router = express.Router(); +import { Router } from "express"; + +const router = Router(); let client: Client | undefined; diff --git a/routes/projectsLocal.ts b/routes/projectsLocal.ts index 654e861..2e8bca2 100644 --- a/routes/projectsLocal.ts +++ b/routes/projectsLocal.ts @@ -1,14 +1,17 @@ import logger from "../utils/logger"; -import express from "express"; -import fs from "fs"; -const router = express.Router(); +import { Router } from "express"; +import { readFile } from "fs"; +import path from "path"; + +const router = Router(); +const FILE_PATH: string = path.resolve(__dirname, "../data.json"); router.get("/", (req: any, res: any) => { if (req.query) { logger.warn("Query parameters ignored"); } - - fs.readFile("../data.json", "utf8", (error: any, content: any) => { + + readFile(FILE_PATH, "utf8", (error: any, content: any) => { if (error) { logger.error("Error reading data.json"); return res.status(500).send("Error reading file"); @@ -24,7 +27,7 @@ router.get("/team", (req: any, res: any) => { return; } - fs.readFile("../data.json", "utf8", (error: any, content: any) => { + readFile(FILE_PATH, "utf8", (error: any, content: any) => { if (error) { logger.error("Error reading data.json"); return res.status(500).send("Error reading file"); @@ -55,7 +58,7 @@ router.get("/cohort", (req: any, res: any) => { return; } - fs.readFile("../data.json", "utf8", (err: any, data: any) => { + readFile(FILE_PATH, "utf8", (err: any, data: any) => { if (err) { logger.error("Error reading data.json"); res.send("Error reading file").status(500); @@ -87,7 +90,7 @@ router.get("/name", (req: any, res: any) => { return; } - fs.readFile("../data.json", "utf8", (err: any, data: any) => { + readFile(FILE_PATH, "utf8", (err: any, data: any) => { if (err) { logger.error("Error reading data.json"); res.send("Error reading file").status(500); diff --git a/server.ts b/server.ts index 3c1f79c..acb261a 100644 --- a/server.ts +++ b/server.ts @@ -1,7 +1,6 @@ import { Client } from "pg"; import activateDb from "./db"; import logger from "./utils/logger"; -import projectsLocal from "./routes/projectsLocal"; import projectsDB from "./routes/projectsDB"; import express from "express";