summary refs log tree commit diff
path: root/src/middlewares/Authentication.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-06-22 18:43:08 +0200
committerGitHub <noreply@github.com>2021-06-22 18:43:08 +0200
commite52597798199d9de8a791723ef6ec37ce08703aa (patch)
tree0b4b14896629a76ee740efdb890d657d15f88b78 /src/middlewares/Authentication.ts
parentMerge pull request #158 from fosscord/l10n_master (diff)
parent:art: clean up code (diff)
downloadserver-e52597798199d9de8a791723ef6ec37ce08703aa.tar.xz
Merge pull request #157 from Umimaso/widget
feat: add widget endpoints, routing for unversioned api requests
Diffstat (limited to 'src/middlewares/Authentication.ts')
-rw-r--r--src/middlewares/Authentication.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/middlewares/Authentication.ts b/src/middlewares/Authentication.ts

index 630a45ff..4b0f2b38 100644 --- a/src/middlewares/Authentication.ts +++ b/src/middlewares/Authentication.ts
@@ -3,11 +3,12 @@ import { HTTPError } from "lambert-server"; import { checkToken, Config } from "@fosscord/server-util"; export const NO_AUTHORIZATION_ROUTES = [ - "/api/v8/auth/login", - "/api/v8/auth/register", - "/api/v8/webhooks/", - "/api/v8/gateway", - "/api/v8/experiments" + /^\/api(\/v\d+)?\/auth\/login/, + /^\/api(\/v\d+)?\/auth\/register/, + /^\/api(\/v\d+)?\/webhooks\//, + /^\/api(\/v\d+)?\/gateway/, + /^\/api(\/v\d+)?\/experiments/, + /^\/api(\/v\d+)?\/guilds\/\d+\/widget\.(json|png)/ ]; declare global { @@ -22,7 +23,7 @@ declare global { export async function Authentication(req: Request, res: Response, next: NextFunction) { if (!req.url.startsWith("/api")) return next(); if (req.url.startsWith("/api/v8/invites") && req.method === "GET") return next(); - if (NO_AUTHORIZATION_ROUTES.some((x) => req.url.startsWith(x))) return next(); + if (NO_AUTHORIZATION_ROUTES.some((x) => x.test(req.url))) return next(); if (!req.headers.authorization) return next(new HTTPError("Missing Authorization Header", 401)); try {