Rooni commited on
Commit
7b1a25a
·
verified ·
1 Parent(s): d3426f9

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +22 -5
server.js CHANGED
@@ -1,18 +1,35 @@
1
  const express = require('express');
2
  const proxy = require('express-http-proxy');
 
3
  const app = express();
4
- const targetUrl = 'https://chatgpt.com/';
 
 
 
 
 
 
 
 
 
5
 
6
  app.use('/', proxy(targetUrl, {
7
  proxyReqPathResolver: (req) => {
8
- return req.originalUrl;
9
  },
10
  proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
11
- // Установите заголовки, которые могут потребоваться для корректной работы сайта
12
- proxyReqOpts.headers['Host'] = new URL(targetUrl).host;
13
- proxyReqOpts.headers['Referer'] = targetUrl;
14
  return proxyReqOpts;
15
  },
 
 
 
 
 
 
 
 
16
  }));
17
 
18
  const port = 7860;
 
1
  const express = require('express');
2
  const proxy = require('express-http-proxy');
3
+ const url = require('url');
4
  const app = express();
5
+ const targetUrl = 'https://chatgpt.com/';
6
+
7
+ // Функция для перезаписи URL в HTML-ответах
8
+ function rewriteHtmlUrls(body, req) {
9
+ const parsedUrl = url.parse(req.url);
10
+ return body.toString().replace(
11
+ new RegExp('(https?:)?//' + url.parse(targetUrl).host, 'g'),
12
+ req.protocol + '://' + req.headers.host + parsedUrl.pathname
13
+ );
14
+ }
15
 
16
  app.use('/', proxy(targetUrl, {
17
  proxyReqPathResolver: (req) => {
18
+ return req.originalUrl;
19
  },
20
  proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
21
+ proxyReqOpts.headers['Host'] = new URL(targetUrl).host;
22
+ proxyReqOpts.headers['Referer'] = targetUrl;
 
23
  return proxyReqOpts;
24
  },
25
+ userResDecorator: (proxyRes, proxyResData, userReq, userRes) => {
26
+ const contentType = proxyRes.headers['content-type'];
27
+ if (contentType && contentType.includes('text/html')) {
28
+ const body = rewriteHtmlUrls(proxyResData, userReq);
29
+ return body;
30
+ }
31
+ return proxyResData;
32
+ },
33
  }));
34
 
35
  const port = 7860;