Spaces:
Running
Running
Update server.js
Browse files
server.js
CHANGED
@@ -1,35 +1,21 @@
|
|
1 |
const express = require('express');
|
2 |
-
const
|
3 |
-
|
4 |
const app = express();
|
5 |
-
const targetUrl = 'https://chatgpt.com/';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
//
|
8 |
-
|
9 |
-
const proxyUrl = req.protocol + '://' + req.get('host');
|
10 |
-
const bodyString = body.toString('utf8'); // Преобразуем буфер в строку UTF-8
|
11 |
-
const newBody = bodyString.replace(new RegExp(targetUrl, 'g'), proxyUrl);
|
12 |
-
return Buffer.from(newBody, 'utf8'); // Преобразуем строку обратно в буфер UTF-8
|
13 |
-
}
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
return url.parse(req.url).path;
|
18 |
-
},
|
19 |
-
proxyReqOptDecorator: (proxyReqOpts, srcReq) => {
|
20 |
-
proxyReqOpts.headers['Host'] = new URL(targetUrl).host;
|
21 |
-
proxyReqOpts.headers['Referer'] = targetUrl;
|
22 |
-
return proxyReqOpts;
|
23 |
-
},
|
24 |
-
userResDecorator: (proxyRes, proxyResData, userReq, userRes) => {
|
25 |
-
const contentType = proxyRes.headers['content-type'];
|
26 |
-
if (contentType && contentType.includes('text/html')) {
|
27 |
-
const body = rewriteURLs(proxyResData, userReq);
|
28 |
-
return body;
|
29 |
-
}
|
30 |
-
return proxyResData;
|
31 |
-
},
|
32 |
-
}));
|
33 |
|
34 |
const port = 7860;
|
35 |
app.listen(port, () => {
|
|
|
1 |
const express = require('express');
|
2 |
+
const puppeteer = require('puppeteer');
|
3 |
+
|
4 |
const app = express();
|
5 |
+
const targetUrl = 'https://chatgpt.com/';
|
6 |
+
|
7 |
+
app.get('/', async (req, res) => {
|
8 |
+
const browser = await puppeteer.launch();
|
9 |
+
const page = await browser.newPage();
|
10 |
+
await page.goto(targetUrl);
|
11 |
+
const html = await page.content();
|
12 |
+
await browser.close();
|
13 |
|
14 |
+
// Здесь вы можете модифицировать HTML-код, например, заменить URL-адреса
|
15 |
+
const newHtml = html.replace(new RegExp(targetUrl, 'g'), req.protocol + '://' + req.get('host'));
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
res.send(newHtml);
|
18 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
const port = 7860;
|
21 |
app.listen(port, () => {
|