randydev commited on
Commit
1536a0f
·
verified ·
1 Parent(s): e151afc

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +2 -33
index.js CHANGED
@@ -3,6 +3,7 @@ const app = express()
3
  const axios = require('axios')
4
 
5
  const {startServer} = require('./lifestyle');
 
6
  const {GptModelOld} = require('./models.js');
7
 
8
  var Database = require('./database.js');
@@ -11,39 +12,7 @@ app.get('/', (req, res) => {
11
  res.redirect('https://t.me/RendyProjects');
12
  });
13
 
14
- app.use(async (req, res, next) => {
15
- const dbClient = new Database("AkenoXJs", "FastJsAPI");
16
- const xForwardedFor = req.headers['x-forwarded-for'];
17
- const xRealIP = req.headers['x-real-ip'];
18
- const cfConnectingIP = req.headers['cf-connecting-ip'];
19
-
20
- let realIP = req.ip;
21
-
22
- if (xForwardedFor) {
23
- realIP = xForwardedFor.split(',')[0].trim();
24
- }
25
- else if (xRealIP){
26
- realIP = xRealIP;
27
- }
28
- else if (cfConnectingIP) {
29
- realIP = cfConnectingIP;
30
- }
31
-
32
- req.realIP = realIP;
33
- const isBlocked = await dbClient.CheckIsBlocked(realIP)
34
- if (isBlocked && isBlocked.blocked === true) {
35
- return res.status(403).send("Access denied: IP is blocked");
36
- }
37
- if (req.path === '/env') {
38
- console.log("check path /env");
39
- await dbClient.AddIpisBlocked(realIP)
40
- return res.status(403).send("Access denied: IP is blocked..");
41
- }
42
-
43
- await dbClient.IPAddressAndUpdate(realIP);
44
- console.log(`Real IP address is: ${realIP}, header: ${xForwardedFor ? "x-forwarded-for" : xRealIP ? "x-real-ip" : cfConnectingIP ? "cf-connecting-ip" : "req.ip"} `);
45
- await next();
46
- });
47
 
48
  app.get('/api/test', async (req, res) => {
49
  try {
 
3
  const axios = require('axios')
4
 
5
  const {startServer} = require('./lifestyle');
6
+ const {CheckMilWare} = require('./midware.js');
7
  const {GptModelOld} = require('./models.js');
8
 
9
  var Database = require('./database.js');
 
12
  res.redirect('https://t.me/RendyProjects');
13
  });
14
 
15
+ app.use(await CheckMilWare(app));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  app.get('/api/test', async (req, res) => {
18
  try {