1

I don't want to monkey patch Padrino.

I still want to be able to use the command padrino start -d from the command line.

I want to get SSL up and running within padrino. Within Sinatra I just do:

Rack::Handler::WEBrick.run MyServer, MyServerOptionsWithAppropriateSSLStuffEtc

I found the file deep inside the Padrino core that handles setting these options, but I really don't want to monkey patch the application.

Ideally I'd like there to be be some way I could set the options within my Padrino::Application subclass.

So far I haven't found any documentation on how to do this, or if this is even possible.

Jesse Earle
  • 1,622
  • 1
  • 11
  • 13

2 Answers2

1

mmm, you should be able to do the same.

In your project folder you should see config.ru

Try to edit it removing last line with:

Rack::Handler::WEBrick.run Padrino.application, MyServerOptionsWithAppropriateSSLStuff

Then from command line:

$ rackup
DAddYE
  • 1,719
  • 11
  • 16
0

I know this is old, but in case anybody is trying to do this cleanly, here is what I use:

class MyApplication < ::Sinatra::Base
  # ...

  def self.server_settings
    { key: value, ... }
  end

  # ...
end

You can also inject settings prior to runtime:

MyApplication.class_exec(server_settings) do |server_params|
  def self.server_settings
    server_params
  end
end

I frequently use the second example for injecting a custom logger into my application for specs.

For example:

module CustomLogger
  def logger
    settings.try(:server_settings)[:Logger] || request.logger
  end
end

MyApplication.class_exec(CustomLogger) do |logger_module|
  helpers logger_module
  def self.server_settings
    # global specified in guard/spec helper
    { Logger: $LOGGER }
  end
end

class MyApplication < ::Sinatra::Base
  enable :logging

  get '/' do
    logger.info "FOO"
  end
end

MyApplication.run!

See this source link for more info about server_settings usage in Application::self.run!.

Adam Eberlin
  • 14,005
  • 5
  • 37
  • 49