configure sinatra as a server

145 Views Asked by At

I have written an app in ruby using sinatra. the app works fine and I am testing the post/get request using postman.

Right now I start the app using the command rackup but it starts the server locally on the port 9292. using postman, I send the POST on localhost:9292

I would like to test the app when access from another computer. I expect something using POSTMAN sending a POST on http://182.12.34.1:9292 but I didn't find how to do this.

config.ru

load './app/init.rb'
run Sinatra::Application

Procfile

web: bundle exec unicorn -p $PORT -E $RACK_ENV -c ./config/unicorn.rb

Any idea, how to switch from local test to a server ?

Thansks

2

There are 2 best solutions below

0
On

Did you perhaps listen to localhost only in the config?

You need to bind the host to 0.0.0.0 otherwise it will only only be available locally...

0
On

The easiest way is to use an existing tool like ngrok or localtunnel.

If you have npm installed, then you can do this in a new terminal:

sudo npm install -g localtunnel
lt --port 9292

It will then give you a URL that you can share. Keep in mind these two things:

  1. The URL is only valid as long as the localtunnel process is running
  2. You still need to have your server running on localhost:9292 for it to work.