问题描述:

Is it possible to run Rack and specify that it should look for config.ru from one of the project's Gem dependencies rather than the project's files on the local filesystem?

I'm sure this is a 'wrong' pattern, but we've got project A that has a load of front-end static resources. Project B is a Sinatra app that provides the backend services for that web UI to call upon. We separated them into two projects so A could depend on a particular version of B, and be insulated from breaking changes.

B contains the Sinatra app, and the config.ru which defines what Sinatra endpoints are mapped to which paths, and additionally that the static resources should be served too.

A has the thinnest sliver of Ruby, essentially just depending on B via a Gemfile.

We want someone to be able to clone project A, do a bundle install, and then run rackup and have Rack use the config.ru inside B's Gem to decide how to configure itself.

网友答案:

The "rackup" command can take options for the include path and a specific library as well as the path to the config file you want to run, so you should be able to pull it off…

Usage: rackup [ruby options] [rack options] [rackup config]

Ruby options:
  ...
  -I, --include PATH       specify $LOAD_PATH (may be used more than once)
  -r, --require LIBRARY    require the library, before executing your script

If that doesn't work for you, you may need to provide more details on what you are trying to do

相关阅读:
Top