08.2 Paid Reverse Proxy

So you've been testing out the app and it seems to be doing what you want, but you're tired of having to change the URL all the time?? Yeah, I feel you. Kinda makes it unusable for a day-to-day SMS service, huh? Well, the cheapest plan on ngrok is $60 for the year, and while yes, that is more than we'd like it to be, I look at it this way: I've got a private/Google-free phone that I'm only paying $15 dollars a month for (plus $1 per Twilio number). If I have two Twilio numbers, with ngrok's $5, that bumps my phone bill up to $22 a month. Now, I'm not sure what cellular plans in your area cost, but here, $22 /month isn't bad, especially for the setup I've got going, so I'll take it.

Please know: I am in no way affiliated with ngrok and I receive absolutely nothing from them nor have I ever even talked to anyone connected to them in any way. As a developer, I just like the service and what it does, so I use it.

  1. Go to ngrok.com and sign up for the Basic account (privacy.com cards are accepted)

  2. Once logged in, click "Your Authtoken" in the menu on the left side

  3. Copy that authtoken to the clipboard.

  4. In a terminal, type: echo "<authtoken>" >> ngrokTokenPut your token in the quotes.

  5. Start a python server: python3 -m http.server

(on the Raspberry Pi now)

  1. Stop whatever you've got running, if anything.

  2. Navigate to your home folder: cd ~

  3. Grab the token: wget http://192:168.X.XXX:8000/ngrokToken

  4. Authorize ngrok on the Pi: ngrok authtoken $(cat ./ngrokToken)

  5. Make sure it worked: ngrok http 4001

You should see your username and "Plan: Basic" on the second line now

6. Delete the file with the token: rm ./ngrokToken

Alternatively, you could just make a file called ngrok.yml in /home/<username>/.ngrok2/ and put authtoken: <your-token>, but hey, do you

So now we've got our Pi authorized to use our ngrok account, let's make a static URL at ngrok.com.

  1. At ngrok.com, log in and click Domains in the menu on the left.

  2. Click the + Create a Domain button.

  3. Enter any domain you want to use for your server. I just generated a random string of letters and numbers and used that. I figured there's less of a chance of someone guessing that, but I don't know. I'm only going to have to type it out once or twice so it doesn't matter.

  4. Click Continue at the bottom and you should now have something like <your-domain>.ngrok.io.

  5. Click Configurations in the menu now.

  6. Add a configuration named shSMS and add the module Request Headers

  7. There should be two textfields, "Name" and "Value".

  8. In "Name", put enc

  9. In "Value", put the exact same SECRET_KEY you've used previously for your .env files.

  10. Save and make sure the little switch is set to "on" for the Request Headers module.

We should be all set now, the only difference is instead of starting our server with ngrok http 4001, we're going to do:

ngrok http --hostname=<your-domain>.ngrok.io 4001

Last time we should have to update these now:

  1. Update baseURL in your Twilio funcion with this new <your-domain>.ngrok.io URL.

  2. Update the REACT_APP_SMS_SERVER_URL in the .env in your shsms-frontend folder and rebuild the app/install on device.

(on the Raspberry Pi)

  1. Navigate to the shsms-backend folder: cd ~/shSMS/shsms-backend

  2. Open two terminals with tmux if they're not already open: tmux new -s shSMS Then Ctrl + b, %

  3. Start the shSMS server: node server.js

  4. Switch to the other side and start ngrok with our custom domain:

  • Ctrl + b, o

  • ngrok http --hostname=<your-domain>.ngrok.io 4001

We're actually done for real now!! 🎉 Like, all the way done. Can you believe it?? If you followed all the directions plus the steps about home firewalls in Michael Bazzell's book, we've now got a pretty locked-down, fully self hosted SMS server running on a Raspberry Pi behind a firewall and most importantly, we control it! Yeah, it's ours! When you send an SMS/MMS, it gets saved directly to our database! No more hitting up Salesforce with that shit.

Last updated