summary refs log tree commit diff
path: root/src/middlewares
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-23 20:48:25 +0200
committerGitHub <noreply@github.com>2021-05-23 20:48:25 +0200
commite1f0eb3c2a0b302641b0b88afcd8d29d85821a2c (patch)
tree29c5d85351363f7f189a61e2da52c214e597c0dd /src/middlewares
parentMerge pull request #146 from luth31/upstream (diff)
parentFix: No more type casting required, rather take the gernics (diff)
downloadserver-e1f0eb3c2a0b302641b0b88afcd8d29d85821a2c.tar.xz
Merge pull request #147 from DiegoMagdaleno/master
New way to do config no more hardcoded localhost
Diffstat (limited to 'src/middlewares')
-rw-r--r--src/middlewares/Authentication.ts6
-rw-r--r--src/middlewares/GlobalRateLimit.ts5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/middlewares/Authentication.ts b/src/middlewares/Authentication.ts

index 0ecc1bc0..050c427f 100644 --- a/src/middlewares/Authentication.ts +++ b/src/middlewares/Authentication.ts
@@ -1,6 +1,7 @@ import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; import { checkToken } from "@fosscord/server-util"; +import * as Config from "../util/Config" export const NO_AUTHORIZATION_ROUTES = [ "/api/v8/auth/login", @@ -27,7 +28,10 @@ export async function Authentication(req: Request, res: Response, next: NextFunc // TODO: check if user is banned/token expired try { - const decoded: any = await checkToken(req.headers.authorization); + + const { jwtSecret } = Config.apiConfig.getAll().security; + + const decoded: any = await checkToken(req.headers.authorization, jwtSecret); req.token = decoded; req.user_id = decoded.id; diff --git a/src/middlewares/GlobalRateLimit.ts b/src/middlewares/GlobalRateLimit.ts
index fc121911..38098981 100644 --- a/src/middlewares/GlobalRateLimit.ts +++ b/src/middlewares/GlobalRateLimit.ts
@@ -1,5 +1,6 @@ import { NextFunction, Request, Response } from "express"; -import Config from "../util/Config"; +import * as Config from '../util/Config' +import crypto from "crypto"; // TODO: use mongodb ttl index // TODO: increment count on serverside @@ -43,7 +44,7 @@ export async function GlobalRateLimit(req: Request, res: Response, next: NextFun } export function getIpAdress(req: Request): string { - const { forwadedFor } = Config.get().security; + const { forwadedFor } = Config.apiConfig.getAll().security; const ip = forwadedFor ? <string>req.headers[forwadedFor] : req.ip; return ip.replaceAll(".", "_").replaceAll(":", "_"); }