0

So I have a web application developed in Ruby on Rails 4.0 and accessible on my local PC via localhost:3000 (after I start the rails server by running rails s in cmd at the root of the app). It is of moderate complexity, has DB interaction (I use PostgreSQL) etc.

Now, the application has zero utility unless I can make it work at the network level. I need any user in the network (initially all of them and then I will restrict visibility to only a few of them - I know how to do it) to be able to access my application either by using my IP (something like 1.1.34.45/index) or, preferably, a friendly name such as: myapp/index)

I imagine this can be done by making some quick adjustments but would need your guidelines as to how and what to change so that all network users can access the app found on my local PC in the same way I do it from my PC. Many thanks in advance

2
  • You need to configure your nginx/apache2 server on local system. digitalocean.com/community/tutorials/…
    – RAJ
    Aug 4, 2014 at 7:19
  • What's the intention? To make a development version of the app available for user testing (technically, a staging server), or to publish a production grade app for internal use? There's different answers, depending on intent. I'll provide an answer below for making a dev server available locally. And... What's the local DNS? Do machines (including yours) change IP addresses unpredictably? You'll need some kind of directory service with name-to-ip mapping to work out where your server is now.
    – JezC
    Aug 4, 2014 at 9:21

3 Answers 3

2

If the app is available at localhost:3000 than it should also be available via 1.1.34.45:3000. Assuming Port 3000 is open on your local PC and 1.1.34.45 is your current IP address within your local network.

Note that a Webbrick server is not really something you want to use in production. But for tests it might be okay to open that app to your local network.

2
  • Thank you spickermann, it worked as you said! Now, why not using the Webbbrick server? Any tips on that on what better option there is and why?
    – Samy
    Aug 4, 2014 at 7:48
  • WEBrick is notoriously slow - only loading individual files / assets, which takes a long time. This methodical loading procedure is good for development, but seriously too slow for production Aug 4, 2014 at 8:03
0

Maybe you will find usefull proxylocal gem.

"ProxyLocal could proxy your local web-server and make it publicly available over the internet."

Official site

0

To make a development app available for use within a firewalled business environment, consider using the heroku tools, especially "foreman". You can configure foreman to use a faster web server (unicorn is a good choice, IMO), to run on port 3000 or 500 or whatever... But foreman will then need to stay running, until you kill it. When killed, you offer no service. And... when running, it uses Rails "development" mode. There are things you might do in development mode, that you wouldn't do for production - e.g. optionally using the gem "better_errors", which potentially helps you track down and fix problems, but would also mean that any of your user base can also dig into the code, change the database at low level, etc - if they trigger an error. If you manage your Gemfile properly, then production mode won't give access to developer tools.

Personally, I make testing versions of an app available to other users by creating a "staging" branch in my source code repo. I then run code in that staging branch on a server configured for production use, but using the staging branch not the master branch. That way, I can demo the app changes to interested users without compromising the live server, or sharing a potentially risk development service.

The most basic steps? Note that there is a meaningful difference between single and double quotes in the commands below. If you use a double quote on the Procfile line, you will get the server starting fixed at port 3000. With a single quote, you can set an environment parameter to configure which port it is on - useful when trying to use the same configuration process in dev, staging and production.

install heroku toolbelt

add "gem 'unicorn'" to your Gemfile:

echo "" >> Gemfile
echo "gem 'unicorn'" >> Gemfile

Set up the Procfile for foreman:

echo 'web: unicorn -c config/unicorn.rb -p ${PORT:=3000}' > Procfile

And set up the unicorn configuration file:

cat > config.unicorn.rb << HERE
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end
HERE

and then run foreman start to get a threaded higher performance development web server on Port 3000.

When you're ready, make a staging branch, and set up a more complete staging server.

But the real question... why not just run this on a service like Heroku? If you have any kind of user registration/login process, you can control access. And heroku will gleefully give you dev, staging and production servers. Keep the data under 10MB (IIRC) and you can use it all for free. Does the data (perhaps for regulatory compliance) have to stay inside the firewall on the local network?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.