Wednesday, July 06, 2016

Expose Local Rails App to the Public Internet

1. Install NodeJS if your machine does not have it installed.

2. Install Localtunnel.
    npm install -g localtunnel

3. Start your rails app on your machine
rails s

4. Request a tunnel to your local server:

lt --port 3000

5. Copy the URL in the output:
your url is: https://cgoyfetijd.localtunnel.me

to access it from any machine.

This gave : 504 Gateway Error (with nginx server version)

Due to security, since Rails 4.2 the local server is not exposed to the network. To fix this, start the server like this :

rails s -b 0.0.0.0

When this is accessed from another machine, the log file shows the error:

Cannot render console from 209.249.19.171! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

In development.rb:

config.web_console.whiny_requests = false

does not work.

Add:

config.web_console.whitelisted_ips = '209.249.19.171'

to allow that particular IP to connect remotely to your local Rails app. To whitelist the whole private network:

config.web_console.whitelisted_ips = '209.249.0.0/16'

References

localtunnel
localtunnel gem

No comments:

Post a Comment