1

假设我有一个 config.ru,例如:

map '/foo' do
  run MyApp
end

和一个 Sinatra 应用程序,例如:

class MyApp < Sinatra::Base
  use Rack::Session::File, key: 'rack.session', domain: 'my.domain.com', path: '/foo', expire_after: 86400 * 14, secret: 'mysecret'
end

如何使 MyApp 与/foo用于访问它的请求目录(在这种情况下)无关?我发现它request.script_name包含这个目录,但我不能将它用于语句的path:参数,use Rack::Session::File因为它在从乘客启动应用程序时尚未定义,但仅在稍后将请求发送到应用程序时才定义。

4

1 回答 1

1

Unfortunately it's impossible even with dirty hacks.

So I suppose it's possible to do via two different ways:

  1. External configuration file e.g. routes.yml (config.ru uses it for map statement, application to discover such prefix in url);
  2. Environment variable (I've chosen this because it's easy to configure on Heroku.
于 2012-11-18T19:11:33.707 回答