How to install Tor to Heroku so I can use a socks5 flag

Viewed 323

So I'm trying to figure out how to install Tor to my Node.js app. I'm deploying this app to Heroku. I'm trying to use Puppeteer and the --proxy-server flag to create an IP rotation but I need Tor in my project to access the socks5 address. Here's my code:

let portList = [9050, 9052, 9053, 9054, 9055, 9056, 9057, 9058, 9059, 9060];
let spoofPort = portList[Math.floor(Math.random()*portList.length)];
puppeteerExtra.use(pluginStealth());

const browser = await puppeteerExtra.launch({ headless: true, args: [                
'--no-sandbox', 
'--disable-setuid-sandbox', 
'--proxy-server=socks5://127.0.0.1:' + spoofPort,                                      
]});

const page = await browser.newPage();

await page.goto(`pageURL`);   

I tried to just install a Tor Heroku buildpack (https://elements.heroku.com/buildpacks/todokku/heroku-buildpack-tor-proxy) but the flag still didn't work. How do I install Tor properly?

1 Answers

Instead of using https://elements.heroku.com/buildpacks/todokku/heroku-buildpack-tor-proxy just add heroku apt buildpack.

command

To use the latest stable version of apt buildpack

heroku buildpacks:add --index 1 heroku-community/apt
  • Then create a file with name Aptfile then write contain of the file as tor
  • so it will install tor on heroku.
  • Now heroku will generate a random port to start our application.
  • Then create a empty folder with any name to create a torrc file with our application starts
  • create a bash script in the root directory.

create-torrc.sh

echo "HiddenServiceDir ./hidden_service" >> ./hidden_service/torrc
echo "HiddenServicePort 80 127.0.0.1:$PORT" >> ./hidden_service/torrc
tor -f ./hidden_service
  • create a Procfile
web: node server.js | bash create-torrc.sh

Here is the example of my repository Tor-Onion-Service-On-Heroku

Related