summary refs log tree commit diff
path: root/src/Server.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-07-01 09:33:54 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-07-01 09:33:54 +0200
commitefc522a0c6a08e60de5efce0e076d61445fd9627 (patch)
tree1b82b406c497922d49b84be6febdb0438af1e6a6 /src/Server.ts
parent:construction: rate limit (diff)
downloadserver-efc522a0c6a08e60de5efce0e076d61445fd9627.tar.xz
:construction: rate limit
Diffstat (limited to 'src/Server.ts')
-rw-r--r--src/Server.ts8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Server.ts b/src/Server.ts

index c1e66bfd..54c8db0d 100644 --- a/src/Server.ts +++ b/src/Server.ts
@@ -13,6 +13,7 @@ import express, { Router, Request, Response } from "express"; import fetch, { Response as FetchResponse } from "node-fetch"; import mongoose from "mongoose"; import path from "path"; +import RateLimit from "./middlewares/RateLimit"; // this will return the new updated document for findOneAndUpdate mongoose.set("returnOriginal", false); // https://mongoosejs.com/docs/api/model.html#model_Model.findOneAndUpdate @@ -54,7 +55,8 @@ export class FosscordServer extends Server { db.collection("roles").createIndex({ id: 1 }, { unique: true }), db.collection("emojis").createIndex({ id: 1 }, { unique: true }), db.collection("invites").createIndex({ code: 1 }, { unique: true }), - db.collection("invites").createIndex({ expires_at: 1 }, { expireAfterSeconds: 0 }) // after 0 seconds of expires_at the invite will get delete + db.collection("invites").createIndex({ expires_at: 1 }, { expireAfterSeconds: 0 }), // after 0 seconds of expires_at the invite will get delete + db.collection("ratelimits").createIndex({ created_at: 1 }, { expireAfterSeconds: 1000 }) ]); } @@ -67,6 +69,7 @@ export class FosscordServer extends Server { this.app.use(CORS); this.app.use(Authentication); + this.app.use(RateLimit({ count: 10, error: 10, window: 5 })); this.app.use(BodyParser({ inflate: true, limit: 1024 * 1024 * 2 })); const languages = await fs.readdir(path.join(__dirname, "..", "locales")); const namespaces = await fs.readdir(path.join(__dirname, "..", "locales", "en")); @@ -91,6 +94,9 @@ export class FosscordServer extends Server { const prefix = Router(); // @ts-ignore this.app = prefix; + prefix.use("/guilds/:id", RateLimit({ count: 10, window: 5 })); + prefix.use("/webhooks/:id", RateLimit({ count: 10, window: 5 })); + prefix.use("/channels/:id", RateLimit({ count: 10, window: 5 })); this.routes = await this.registerRoutes(path.join(__dirname, "routes", "/")); app.use("/api", prefix); // allow unversioned requests