Support sub-urls #136

soupmatt opened this Issue May 9, 2011 · 8 comments


None yet
6 participants

soupmatt commented May 9, 2011

It would be nice to support sub-urls when mapping the applications. The use case for me is we have two apps that live under the same domain name that are closely related. One is a rails app with an admin interface, and the other is a sinatra app that is the public facing part of the site. In production, these apps are make like this: - the rails app - the sinatra app

It would be great to add support for this in pow.

cd ~/.pow
ln -s /path/to/foo foo
ln -s /path/to/bar foo\/bar

codykrieger commented May 10, 2011

I haven't actually tried this, but it should work (or something close to it).

# if you're using rvm
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
    rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
    rvm_lib_path = File.join(rvm_path, 'lib')
    $LOAD_PATH.unshift rvm_lib_path
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    # RVM is unavailable at this point.
    raise "RVM ruby lib is currently unavailable."

ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __FILE__)
require 'bundler/setup'

require ::File.expand_path('../bar/app.rb',  __FILE__)
require ::File.expand_path('../config/environment',  __FILE__)

run \
  "/"       => YourRailsAppName::Application,
  "/bar" => Sinatra::Application

That is one crazy :). I've forked the project and I am going to look into adding support for more rich urls in the symlinks that go under ~/.pow. I'd like to see if I can get a full working. This would allow for easy config for future support for ssl as well.


sj26 commented May 13, 2011

I'd +1 codykrieger's approach. Adding additional configuration for mounting on URL paths means you may as well start using Apache or nginx again. If you want to use Pow and mount multiple applications on a domain, use a rack config to compose the applications:

require 'rack'

run \
  "/" => Rack::Builder.parse_file('').first,
  "/bar" => Rack::Builder.parse_file('').first

See the full gist:


josh commented May 13, 2011

I agree with @sj26

Thanks guys. I'll take a look at the Rack API and use that instead.

Has anybody figured out how to do this with two Rails apps? Below is the file I am using written based on the suggestion from @sj26.

require 'rack'

run \
  "/app"  => Rack::Builder.parse_file('app1/').first,
  "/"         => Rack::Builder.parse_file('app2/').first

However, this solution ( using two Rails apps ) gives the following error:

RuntimeError: You cannot have more than one Rails::Application
~/.rvm/gems/ruby-1.9.2-p318@wa/gems/railties-3.1.4/lib/rails/application.rb:45:in inherited' ~/Library/Application Support/Pow/Hosts/wa/app2/config/application.rb:11:inmodule:App2'
~/Library/Application Support/Pow/Hosts/wa/app2/config/application.rb:10:in <top (required)>' ~/.rvm/gems/ruby-1.9.2-p318@wa/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:240:inrequire'
~/.rvm/gems/ruby-1.9.2-p318@wa/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:240:in `block in require'

soupmatt commented Apr 5, 2012

You'll have to run them as separate apps. I would recommend putting a constant for the location of the other app in config/environments/*.rb or in a yaml file so you can vary the location between dev and prod. That way you can run the apps separately under pow. I am currently using this technique and it works well.


sj26 commented Apr 7, 2012

This piqued my curiosity so I made a nack-inspired rack-process gem which lets you mount rack applications in different processes as a rack application. This should let you mount more than one rails application under a single host using pow. Create a directory with a something like:

require 'rack'
require 'rack-process'

run \
  "/first" =>'/path/to/rails-app-1'),
  "/second" =>'/path/to/rails-app2')

Link it up to pow and you should be able to access the applications as you expect.

The gem isn't going to be resilient at all yet, it was just a plaything. It's been designed with single-threaded use only in mind, but so is rails (mostly; dare you remove Rack::Lock?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment