Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const cors = require('cors');
|
| 3 |
+
const { connect } = require("puppeteer-real-browser");
|
| 4 |
+
const recaptchav3 = require('./endpoints/recaptchav3');
|
| 5 |
+
|
| 6 |
+
const app = express();
|
| 7 |
+
const port = process.env.PORT || 7860;
|
| 8 |
+
|
| 9 |
+
app.use(cors());
|
| 10 |
+
app.use(express.json());
|
| 11 |
+
|
| 12 |
+
const MAX_CONCURRENT = 5;
|
| 13 |
+
let active = 0;
|
| 14 |
+
|
| 15 |
+
async function createBrowser() {
|
| 16 |
+
const { browser, page } = await connect({
|
| 17 |
+
headless: false,
|
| 18 |
+
args: [
|
| 19 |
+
'--no-sandbox',
|
| 20 |
+
'--disable-setuid-sandbox',
|
| 21 |
+
'--disable-dev-shm-usage',
|
| 22 |
+
'--disable-accelerated-2d-canvas',
|
| 23 |
+
'--no-first-run',
|
| 24 |
+
'--no-zygote',
|
| 25 |
+
'--disable-gpu',
|
| 26 |
+
'--window-size=1920,1080'
|
| 27 |
+
],
|
| 28 |
+
connectOption: { defaultViewport: null }
|
| 29 |
+
});
|
| 30 |
+
return { browser, page };
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
app.post('/recaptchav3', async (req, res) => {
|
| 34 |
+
const { url, siteKey, action } = req.body;
|
| 35 |
+
|
| 36 |
+
if (!url || !siteKey) {
|
| 37 |
+
return res.status(400).json({ status: "error", message: "Missing url or siteKey" });
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (active >= MAX_CONCURRENT) {
|
| 41 |
+
return res.status(429).json({ status: "busy", message: "Server busy" });
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
active++;
|
| 45 |
+
let browserInstance = null;
|
| 46 |
+
|
| 47 |
+
try {
|
| 48 |
+
const { browser, page } = await createBrowser();
|
| 49 |
+
browserInstance = browser;
|
| 50 |
+
|
| 51 |
+
const token = await recaptchav3(page, url, siteKey, action || 'submit');
|
| 52 |
+
|
| 53 |
+
res.json({
|
| 54 |
+
status: "success",
|
| 55 |
+
token: token
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
} catch (error) {
|
| 59 |
+
console.error("Error: ", error.message);
|
| 60 |
+
res.status(500).json({ status: "error", message: error.message });
|
| 61 |
+
} finally {
|
| 62 |
+
if (browserInstance) {
|
| 63 |
+
try { await browserInstance.close(); } catch {}
|
| 64 |
+
}
|
| 65 |
+
active--;
|
| 66 |
+
}
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
app.get('/', (req, res) => res.send("Recaptcha V3 Solver Ready!"));
|
| 70 |
+
|
| 71 |
+
app.listen(port, () => console.log(`Server running on ${port}`));
|