Spaces:
Sleeping
Sleeping
File size: 2,132 Bytes
7de9db0 1099b2e 7de9db0 1099b2e 7de9db0 bf6502f 7de9db0 e9e8235 bf6502f 7de9db0 bf6502f 1099b2e 595911c bf6502f 7de9db0 bf6502f 7de9db0 9056443 1099b2e 7de9db0 | 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 65 66 67 68 | 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}`);
}); |