randydev commited on
Commit
e1a7fd3
·
verified ·
1 Parent(s): b7604ef

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +17 -1
index.js CHANGED
@@ -22,6 +22,19 @@ const startServer = async () => {
22
  });
23
  };
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  app.get('/', (req, res) => {
26
  res.redirect('https://t.me/RendyProjects');
27
  });
@@ -32,7 +45,7 @@ app.use((req, res, next) => {
32
  const cfConnectingIP = req.headers['cf-connecting-ip'];
33
 
34
  let realIP = req.ip;
35
- const BlockedIp = ["103.187.116.9"];
36
 
37
  if (xForwardedFor) {
38
  realIP = xForwardedFor.split(',')[0].trim();
@@ -45,10 +58,13 @@ app.use((req, res, next) => {
45
  }
46
 
47
  req.realIP = realIP;
 
48
  if (BlockedIp.includes(realIP)) {
49
  console.log(`Blocked request from IP address: ${realIP}`);
50
  res.status(403).send("access is blocked");
51
  }
 
 
52
  console.log(`Real IP address is: ${realIP}, header: ${xForwardedFor ? "x-forwarded-for" : xRealIP ? "x-real-ip" : cfConnectingIP ? "cf-connecting-ip" : "req.ip"} `);
53
  next();
54
  });
 
22
  });
23
  };
24
 
25
+ const IPAddressAndUpdate = async (ip) => {
26
+ try {
27
+ const db = await connectToMongoDB();
28
+ const collection = db.collection("FastJsAPI");
29
+ const filter = { ip: ip};
30
+ const update = { $set: { ip: ip } };
31
+ await collection.updateOne(filter, update, { upsert: true });
32
+ console.log("Updated IP Address");
33
+ } catch (error) {
34
+ console.error("Error:", error.message);
35
+ }
36
+ };
37
+
38
  app.get('/', (req, res) => {
39
  res.redirect('https://t.me/RendyProjects');
40
  });
 
45
  const cfConnectingIP = req.headers['cf-connecting-ip'];
46
 
47
  let realIP = req.ip;
48
+ // const BlockedIp = ["103.187.116.9"];
49
 
50
  if (xForwardedFor) {
51
  realIP = xForwardedFor.split(',')[0].trim();
 
58
  }
59
 
60
  req.realIP = realIP;
61
+ /*
62
  if (BlockedIp.includes(realIP)) {
63
  console.log(`Blocked request from IP address: ${realIP}`);
64
  res.status(403).send("access is blocked");
65
  }
66
+ */
67
+ await IPAddressAndUpdate(realIP);
68
  console.log(`Real IP address is: ${realIP}, header: ${xForwardedFor ? "x-forwarded-for" : xRealIP ? "x-real-ip" : cfConnectingIP ? "cf-connecting-ip" : "req.ip"} `);
69
  next();
70
  });