Add user agent blacklist
This commit is contained in:
parent
3592ef97d3
commit
33641ef6f2
|
@ -1,2 +1,3 @@
|
|||
SERVER_PORT=3000
|
||||
SERVER_ADDR=127.0.0.1
|
||||
SERVER_ADDR=127.0.0.1
|
||||
BLACKLIST_UA=Bot|MSIE|Bytespider|Baidu|Sogou|FB_AN|FB_IOS|FB_IAB|Instagram
|
|
@ -5,7 +5,7 @@ import crypto from "crypto";
|
|||
import express from "express";
|
||||
import rateLimit from "express-rate-limit";
|
||||
|
||||
const { SERVER_ADDR = "0.0.0.0", SERVER_PORT = 3000 } = process.env;
|
||||
const { SERVER_ADDR = "0.0.0.0", SERVER_PORT = 3000, BLACKLIST_UA } = process.env;
|
||||
|
||||
const app = express();
|
||||
|
||||
|
@ -15,6 +15,12 @@ app.set("trust proxy", 1);
|
|||
app.set("view engine", "ejs");
|
||||
app.set("views", path.resolve("."));
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (BLACKLIST_UA && req.headers["user-agent"]?.match(new RegExp(`(${BLACKLIST_UA})`, "i")))
|
||||
return;
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.use((req, res, next) => {
|
||||
|
|
Loading…
Reference in New Issue