index.js 941 B

123456789101112131415161718192021222324252627282930313233
  1. const express = require('express');
  2. const { SocksProxyAgent } = require('axios-socks-proxy-agent');
  3. const axios = require('axios');
  4. const app = express();
  5. const port = process.env.PORT || 3000;
  6. // Configure SOCKS proxy agent to use Tor
  7. const agent = new SocksProxyAgent({
  8. hostname: '127.0.0.1',
  9. port: 9050
  10. });
  11. // HTTP Proxy route
  12. app.use('/', async (req, res) => {
  13. const url = req.query.url;
  14. if (!url) {
  15. return res.status(400).send('Please provide a URL to proxy via the "url" query parameter.');
  16. }
  17. try {
  18. const response = await axios.get(url, { httpAgent: agent, httpsAgent: agent });
  19. res.set('Content-Type', response.headers['content-type']);
  20. res.send(response.data);
  21. } catch (error) {
  22. res.status(500).send('Error fetching the requested URL: ' + error.message);
  23. }
  24. });
  25. app.listen(port, () => {
  26. console.log(`HTTP Proxy server is running on port ${port}`);
  27. });