diff --git a/src/middleware/cookiesForAPI.ts b/src/middleware/cookiesForAPI.ts index 0e16c2b4..1121f4c7 100755 --- a/src/middleware/cookiesForAPI.ts +++ b/src/middleware/cookiesForAPI.ts @@ -1,9 +1,15 @@ import { Request, Response } from "express"; -import config from '../../config.json'; import { BAD_REQUEST, INTERNAL_SERVER_ERROR, FORBIDDEN } from 'http-status-codes' import { getConnection } from 'typeorm'; import { User } from "../entities/User"; +if (!findFile('config.json', process.cwd())) { + Logger.get('FS').error(`No config.json exists in ${__dirname}, exiting...`) + process.exit(1); +} + +const config = JSON.parse(readFileSync(findFile('config.json', process.cwd()), 'utf8')) + export async function cookiesForAPI(req: Request, res: Response, next: any) { if (req.cookies.typex_user) { if (typeof req.cookies.typex_user !== 'string') return res.status(BAD_REQUEST).send({ code: BAD_REQUEST, message: "Please clear browser cookies." }) @@ -17,4 +23,4 @@ export async function cookiesForAPI(req: Request, res: Response, next: any) { if (!req.session.user) return res.status(INTERNAL_SERVER_ERROR).send({ code: INTERNAL_SERVER_ERROR, message: "The user that is logged in does not exist" }) } else return res.status(FORBIDDEN).send({ code: FORBIDDEN, message: "Unauthorized" }) return next(); -} \ No newline at end of file +}