WalleGriffkinder commited on
Commit
1c96637
·
verified ·
1 Parent(s): 7a4b1ae

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -4
index.js CHANGED
@@ -4,7 +4,7 @@ import fetch from 'node-fetch';
4
  const app = express();
5
  app.use(express.raw({type: '*/*'}));
6
 
7
- // Hello World на главной
8
  app.get('/', (req, res) => {
9
  res.send('Hello World');
10
  });
@@ -14,8 +14,14 @@ app.all('*', async (req, res) => {
14
  if (req.url === '/') return;
15
 
16
  try {
17
- // Убираем первый слэш и декодируем URL
18
- const targetUrl = decodeURIComponent(req.url.substring(1));
 
 
 
 
 
 
19
 
20
  // Проверяем что это валидный URL
21
  if (!targetUrl.startsWith('http')) {
@@ -45,7 +51,7 @@ app.all('*', async (req, res) => {
45
  res.setHeader(key, value);
46
  });
47
 
48
- // Regular response
49
  const data = await response.buffer();
50
  res.status(response.status);
51
  res.send(data);
 
4
  const app = express();
5
  app.use(express.raw({type: '*/*'}));
6
 
7
+ // Hello World на главной
8
  app.get('/', (req, res) => {
9
  res.send('Hello World');
10
  });
 
14
  if (req.url === '/') return;
15
 
16
  try {
17
+ // Получаем полный URL запроса
18
+ const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
19
+
20
+ // Находим позицию после нашего домена
21
+ const domainEnd = fullUrl.indexOf('/', 8); // пропускаем https://
22
+
23
+ // Извлекаем целевой URL
24
+ const targetUrl = fullUrl.substring(domainEnd + 1);
25
 
26
  // Проверяем что это валидный URL
27
  if (!targetUrl.startsWith('http')) {
 
51
  res.setHeader(key, value);
52
  });
53
 
54
+ // Regular response
55
  const data = await response.buffer();
56
  res.status(response.status);
57
  res.send(data);