miaw / server.js
CiEL7's picture
Upload 4 files
b36894d verified
Raw History Blame Contribute Delete
1.03 kB
import express from 'express';
import fetch from 'node-fetch';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
const PORT = process.env.PORT || 7860;
const FLARESOLVERR_URL = process.env.FLARESOLVERR_URL || 'http://localhost:7860';
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(__dirname));
app.post('/proxy', async (req, res) => {
const url = req.body.url;
const payload = {
cmd: 'request.get',
url: url,
};
try {
const response = await fetch(`${FLARESOLVERR_URL}/v1`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await response.json();
res.json(data);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Request failed' });
}
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});