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.
Go to ngrok.com and sign up for the Basic account (privacy.com cards are accepted)
Once logged in, click "Your Authtoken" in the menu on the left side
Copy that authtoken to the clipboard.
In a terminal, type:
echo "<authtoken>" >> ngrokToken
Put your token in the quotes.Start a python server:
python3 -m http.server
(on the Raspberry Pi now)
Stop whatever you've got running, if anything.
Navigate to your home folder:
cd ~
Grab the token:
wget http://192:168.X.XXX:8000/ngrokToken
Authorize ngrok on the Pi:
ngrok authtoken $(cat ./ngrokToken)
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.
At ngrok.com, log in and click
Domains
in the menu on the left.Click the
+ Create a Domain
button.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.
Click
Continue
at the bottom and you should now have something like<your-domain>.ngrok.io
.Click
Configurations
in the menu now.Add a configuration named shSMS and add the module
Request Headers
There should be two textfields, "Name" and "Value".
In "Name", put
enc
In "Value", put the exact same SECRET_KEY you've used previously for your
.env
files.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:
Update
baseURL
in your Twilio funcion with this new<your-domain>.ngrok.io
URL.Update the
REACT_APP_SMS_SERVER_URL
in the.env
in yourshsms-frontend
folder and rebuild the app/install on device.
(on the Raspberry Pi)
Navigate to the
shsms-backend
folder:cd ~/shSMS/shsms-backend
Open two terminals with tmux if they're not already open:
tmux new -s shSMS
ThenCtrl + b, %
Start the shSMS server:
node server.js
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