mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-05 18:05:08 +00:00
add express rate limiting
This commit is contained in:
@@ -31,6 +31,8 @@ import { SecretManagerServiceClient } from "@google-cloud/secret-manager";
|
||||
import dotenv from "dotenv";
|
||||
import crypto from "crypto";
|
||||
dotenv.config();
|
||||
import rateLimit from "express-rate-limit";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
@@ -51,6 +53,22 @@ let DISCORD_CLIENT_SECRET: string;
|
||||
app.use(express.static(path.join(__dirname, "../../out")));
|
||||
app.use(express.json());
|
||||
|
||||
app.set("trust proxy", 2);
|
||||
app.use(
|
||||
rateLimit({
|
||||
windowMs: 1000, // 1 second
|
||||
max: 20, // 20 requests per IP per second
|
||||
}),
|
||||
);
|
||||
|
||||
app.set("trust proxy", 2);
|
||||
app.use(
|
||||
rateLimit({
|
||||
windowMs: 1000, // 1 second
|
||||
max: 20, // 20 requests per IP per second
|
||||
}),
|
||||
);
|
||||
|
||||
const gm = new GameManager(serverConfig);
|
||||
|
||||
let lobbiesString = "";
|
||||
@@ -208,6 +226,14 @@ app.get("/private_lobby/:id", (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/debug-ip", (req, res) => {
|
||||
res.send({
|
||||
"x-forwarded-for": req.headers["x-forwarded-for"],
|
||||
"real-ip": req.ip,
|
||||
"raw-headers": req.rawHeaders,
|
||||
});
|
||||
});
|
||||
|
||||
app.get("*", function (req, res) {
|
||||
// SPA routing
|
||||
res.sendFile(path.join(__dirname, "../../out/index.html"));
|
||||
|
||||
Reference in New Issue
Block a user