-
Notifications
You must be signed in to change notification settings - Fork 561
Description
update - i've just forked a deployable version to reduce some of the steps below.
hi folks,
i noticed a bunch of you (#140, #172, #135, #120, #119, #88) are struggling to get this working on your own server. below is a free and easy solution!
first, i suggest you get it running locally via the included README instructions:
# 1. install dependencies
npm install # for reference, i used node 16.17.0
# 2. config your email inside lib/config.js (using Gmail as an example)
- host: 'smtp.gmail.com'
- auth: { user: 'youraddress@gmail.com' }
- auth: { pass: make app-specific Gmail password: https://security.google.com/settings/security/apppasswords
# 3. run the server
redis-server # should default to port 6379
node server/app.js # in a new terminal tab! keep redis running separately
# 4. try sending a text message
curl -X POST http://localhost:9090/text \
-d number=<your-cell-phone> \
-d "message=I sent this message for free with Textbelt"
when this works, you're ready to deploy. push this code up to a new PRIVATE GitHub repository (since we added SMTP credentials), or change those hard-coded values to environment variables.
git add .
git commit -m 'prepare textbelt for deploy'
git remote set-url origin https://github.com/yourusername/your_new_repo
deploying a self-hosted version of Textbelt
- create a free account at https://render.com. this is basically like Heroku. i've never used it until today, not a promo.
- click to make a "Web Service" from your dashboard or click New > Web Service from navigation
- auth your GitHub and select the textbelt repository you created
- name your app, e.g. textbelt, then set Environment to
Node, Build Command tonpm install, and Start Command tonode server/app.js - select the free Instance Type
- if you refactored
lib/config.jsto use environment variables, plug those in by clicking Advanced > Add Environment Variable - click Create Web Service at the very bottom
this will build and deploy your code. when it's done, click the URL generated by Render and you should see the "homepage" saying I'm online!.
now for the final task. if you try creating a text message via our previous strategy:
curl -X POST https://your-textbelt-server.onrender.com/text \
-d number=<your-cell-phone> \
-d "message=A free text message with Textbelt on Render"you'll likely get a CANNOT Post response with some HTML markup. i couldn't figure out why Render blocks the request as the server already has CORS enabled.
to fix this, simply modify your code inside server/app.js:
// before
app.post('/text', (req, res) => {
// after
app.get('/text', (req, res) => {Render won't complain about cross origin GET requests. inside your Render project dashboard click "Manual Deploy" to update your server with the /text endpoint HTTP method update.
you'll be up and running in seconds! enjoy.