File size: 2,265 Bytes
e1dfc83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const http = require('http');

const server = http.createServer(async (req, res) => {
    // Wyciągamy api_url z parametrów zapytania
    const parsedUrl = new URL(req.url, `http://${req.headers.host}`);
    const targetUrl = parsedUrl.searchParams.get("api_url");

    if (!targetUrl) {
        res.writeHead(400, { "Content-Type": "text/plain; charset=utf-8" });
        res.end("Podaj api_url w parametrze");
        return;
    }

    // Podmieniamy nagłówki dla Chomika
    const headers = { ...req.headers };
    delete headers["host"];
    headers["origin"] = "https://chomikuj.pl";
    headers["referer"] = "https://chomikuj.pl/";
    headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";

    try {
        // Przechwytujemy body dla POST (dane logowania)
        let body = undefined;
        if (req.method !== "GET" && req.method !== "HEAD") {
            const chunks = [];
            for await (const chunk of req) {
                chunks.push(chunk);
            }
            body = Buffer.concat(chunks);
        }

        // Strzał do Chomika
        const response = await fetch(targetUrl, {
            method: req.method,
            headers: headers,
            body: body,
            redirect: "manual", // Zatrzymujemy przekierowania, żeby złapać ciastka
        });

        // Przepisujemy nagłówki zwrotne
        const responseHeaders = {};
        response.headers.forEach((value, key) => {
            responseHeaders[key] = value;
        });

        // Wstrzykujemy CORS dla Satana
        responseHeaders["access-control-allow-origin"] = req.headers["origin"] || "*";
        responseHeaders["access-control-allow-credentials"] = "true";

        // Odsyłamy odpowiedź
        res.writeHead(response.status, responseHeaders);
        const resBuffer = await response.arrayBuffer();
        res.end(Buffer.from(resBuffer));

    } catch (e) {
        res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
        res.end("Błąd: " + e.message);
    }
});

// WAŻNE: Hugging Face wymaga nasłuchiwania na porcie 7860
server.listen(7860, '0.0.0.0', () => {
    console.log('Proxy Angela śmiga na porcie 7860');
});