This commit is contained in:
Christopher Cookman 2024-09-05 11:51:38 -06:00
parent b7f279f03c
commit 57e1ca6214
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -7,11 +7,6 @@ const port = process.env.SERVER_PORT || 3000;
app.use(express.json());
app.set("trust proxy", 1);
app.use((req, res, next) => {
console.log(`[${new Date().toLocaleString()}] ${req.ip} ${req.method} ${req.url}`);
next();
})
// if blacklist doesnt exist, make the file
if (!fs.existsSync("./blacklist.json")) {
fs.writeFileSync("./blacklist.json", "[]");
@ -20,12 +15,14 @@ if (!fs.existsSync("./blacklist.json")) {
app.use((req, res, next) => { // Blacklist handler
let blacklist = require("./blacklist.json"); // Get it every time to update it
if (blacklist.includes(req.ip)) {
console.log(`[${new Date().toLocaleString()}] ${req.ip} ${req.method} ${req.url} - Blacklisted`);
return res.status(403).json({
code: 403,
message: codes[403].message,
additional: codes[403].description
});
}
console.log(`[${new Date().toLocaleString()}] ${req.ip} ${req.method} ${req.url}`);
next();
})