diff options
author | Marvin Borner | 2020-09-17 22:01:48 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-17 22:01:48 +0200 |
commit | 35ae49c6145b3f29704b0f184ddb142b003f82a0 (patch) | |
tree | 21ab5bcda2a07ccef7774239e231771b07c57e0d /motto/index.js | |
parent | 76fbbc2c6812d78999b20a2de7b419e1f0ed3e94 (diff) |
Added rate limiting
Diffstat (limited to 'motto/index.js')
-rw-r--r-- | motto/index.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/motto/index.js b/motto/index.js index eb1acab..423a19a 100644 --- a/motto/index.js +++ b/motto/index.js @@ -1,7 +1,14 @@ const express = require("express"); const sqlite3 = require("sqlite3"); -const fs = require("fs"); +const rateLimit = require("express-rate-limit"); const app = express(); +// const fs = require("fs"); + +const apiLimiter = rateLimit({ + windowMs: 10 * 60 * 1000, + max: 100, + message: "Access overflow!", +}); app.use(express.urlencoded({ extended: true })); app.use(express.json()); @@ -50,6 +57,8 @@ function insert(main, description, votes) { app.use("/", express.static(__dirname + "/public")); +app.use("/api/", apiLimiter); + app.get("/api/list", (req, res) => { db.all("SELECT * FROM theme ORDER BY votes DESC", (err, all) => { if (err) { @@ -91,5 +100,5 @@ app.on("close", () => { }); create_db(); -console.log("Listening on port 3000"); +console.log("Listening on port 5005"); app.listen(5005); |