Spaces:
Sleeping
Sleeping
Download index.js from CiEL7/testing: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/CiEL7/testing/resolve/main/index.js
- Command line
-
hf download hf://spaces/CiEL7/testing/index.js
-
curl -L -o index.js https://huggingface.co/spaces/CiEL7/testing/resolve/main/index.js
2.13 kB
| import express from 'express'; | |
| import { solveCloudflare, getSakanaCookie, TurnstileSolver } from './solve.js'; | |
| const app = express(); | |
| app.use(express.json()); | |
| const PORT = process.env.PORT || 7860; | |
| // Reuse a single browser instance across requests instead of launching a | |
| // new one every time - much faster for repeated calls. | |
| const turnstileSolver = new TurnstileSolver({ timeout: 60000 }); | |
| app.get('/', (req, res) => { | |
| res.send({ status: 'Server is running' }); | |
| }); | |
| app.post('/solve', async (req, res) => { | |
| const { url, waitForCookie } = req.body || {}; | |
| if (!url) { | |
| return res.status(400).json({ error: 'URL parameter is required' }); | |
| } | |
| try { | |
| // Panggil fungsi solveCloudflare | |
| const result = await solveCloudflare({ | |
| url: url, | |
| headless: 'auto', | |
| timeout: 60, | |
| waitForCookie: waitForCookie | |
| }); | |
| res.json(result); | |
| } catch (error) { | |
| res.status(500).json({ error: error.message }); | |
| } | |
| }); | |
| app.post('/solve_sakana', async (req, res) => { | |
| try { | |
| const result = await getSakanaCookie({ | |
| timeout: 60 | |
| }); | |
| res.json(result); | |
| } catch (error) { | |
| res.status(500).json({ error: error.message }); | |
| } | |
| }); | |
| app.post('/turnstile', async (req, res) => { | |
| const { url, siteKey } = req.body || {}; | |
| if (!url) { | |
| return res.status(400).json({ error: 'url parameter is required' }); | |
| } | |
| try { | |
| // With siteKey: solves against a minimal fake page (fast, works for | |
| // any site if you already know its Turnstile sitekey). | |
| // Without siteKey: loads the real page and waits for the site's own | |
| // Turnstile widget to produce a token (slower, but no sitekey needed). | |
| const result = await turnstileSolver.solve(url, siteKey || null); | |
| res.json(result); | |
| } catch (error) { | |
| res.status(500).json({ success: false, error: error.message }); | |
| } | |
| }); | |
| app.listen(PORT, '0.0.0.0', () => { | |
| console.log(`Server listening on port ${PORT}`); | |
| }); |