Download server.js from TacoManAI/Proxy: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/TacoManAI/Proxy/resolve/main/server.js
- Command line
-
hf download hf://spaces/TacoManAI/Proxy/server.js
-
curl -L -o server.js https://huggingface.co/spaces/TacoManAI/Proxy/resolve/main/server.js
1.52 kB
| const express = require('express'); | |
| const puppeteer = require('puppeteer'); | |
| const app = express(); | |
| const PORT = process.env.PORT || 3000; | |
| app.get('/render', async (req, res) => { | |
| const targetUrl = req.query.url; | |
| if (!targetUrl) { | |
| return res.status(400).send('Error: Missing "url" parameter.'); | |
| } | |
| let browser; | |
| try { | |
| // Launch headless Chromium inside the server | |
| browser = await puppeteer.launch({ | |
| headless: true, | |
| args: [ | |
| '--no-sandbox', | |
| '--disable-setuid-sandbox', | |
| '--disable-dev-shm-usage', | |
| '--disable-gpu' | |
| ] | |
| }); | |
| const page = await browser.newPage(); | |
| // Set a realistic viewport and User-Agent to prevent bot-detection issues | |
| await page.setViewport({ width: 1280, height: 800 }); | |
| await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); | |
| // Go to target URL and wait until the network is idle (JS finished executing) | |
| await page.goto(targetUrl, { | |
| waitUntil: 'networkidle2', | |
| timeout: 30000 | |
| }); | |
| // Capture the fully executed DOM | |
| const renderedHtml = await page.content(); | |
| res.setHeader('Content-Type', 'text/html'); | |
| res.send(renderedHtml); | |
| } catch (error) { | |
| res.status(500).send(`Chromium Error: ${error.message}`); | |
| } finally { | |
| if (browser) { | |
| await browser.close(); | |
| } | |
| } | |
| }); | |
| app.listen(PORT, () => { | |
| console.log(`Chromium render proxy listening on port ${PORT}`); | |
| }); |