Gwuh
This commit is contained in:
parent
b7f279f03c
commit
57e1ca6214
7
index.js
7
index.js
|
@ -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();
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue