Rubymine Thin with SSL options
Asked Answered
D

4

7

I can use THIN with

bundle exec thin start --ssl --ssl-verify --ssl-key-file /private/etc/apache2/ssl/server.key --ssl-cert-file /private/etc/apache2/ssl/server.crt

It works in the console/terminal, perfectly

But when I try to append these options in rubymine under "Run/Debug Configurations" -> "Edit Script Arguments" I get:

/Users/jan/.rbenv/versions/1.9.3-p392/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)  /Users/jan/RubymineProjects/myapp/script/rails server thin -b 0.0.0.0 -p 3000 -e development --ssl-verify --ssl-key-file /private/etc/apache2/ssl/server.key --ssl-cert-file /private/etc/apache2/ssl/server.crt
/Users/jan/.gem/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:33:in `parse!': invalid option: --ssl-verify (OptionParser::InvalidOption)
from /Users/jan/.gem/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:283:in `parse_options'
from /Users/jan/.gem/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:180:in `options'
from /Users/jan/.gem/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:54:in `set_environment'
from /Users/jan/.gem/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:42:in `initialize'
from /Users/jan/.gem/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `new'
from /Users/jan/.gem/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from /Users/jan/RubymineProjects/myapp/script/rails:6:in `require'
from /Users/jan/RubymineProjects/myapp/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'

Process finished with exit code 1 Can anyone help us / me out?

many thanks!

Disk answered 20/6, 2013 at 14:18 Comment(1)
Cannot the ssl key and certificate file be specified in thin's configuration file (YAML)?Paralogism
D
3

I got help here:

http://devnet.jetbrains.com/message/5490676

It seems Rubymine can't parse such arguments, but a workaround is to do this with a Ruby script from Run/Debug Configurations

Disk answered 25/6, 2013 at 8:14 Comment(0)
I
4

Use following way

require 'rack'

SERVER_KEY = File.expand_path('../../ssl-cert/host.key',  __FILE__)
SERVER_PEM = File.expand_path('../../ssl-cert/host.crt',  __FILE__)

# Thin SSL workaround
module Rack
  module Handler
    class Thin
      def self.run(app, options={})
        app = Rack::Chunked.new(Rack::ContentLength.new(app))
        server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
                                    options[:Port] || 3000,
                                    app)
        server.ssl = true
        server.ssl_options = {
            :private_key_file => SERVER_KEY,
            :cert_chain_file => SERVER_PEM
        }
        yield server if block_given?
        server.start
      end
    end
  end
end
# Workaround end

APP_PATH = File.expand_path('../../config/application',  __FILE__)
require File.expand_path('../../config/boot',  __FILE__)
require 'rails/commands'
Interviewer answered 5/4, 2015 at 9:46 Comment(1)
From this Github comment, if you want Thin to use its built-in self signed certificate, you can pass nil to :private_key_file and :cert_chain_file.Letendre
D
3

I got help here:

http://devnet.jetbrains.com/message/5490676

It seems Rubymine can't parse such arguments, but a workaround is to do this with a Ruby script from Run/Debug Configurations

Disk answered 25/6, 2013 at 8:14 Comment(0)
I
1

The option --ssl-verify should not be used

Interviewer answered 4/4, 2015 at 13:59 Comment(0)
A
0

Apparently this can actually be pulled off by adding a Procfile and the gem foreman, as in this set of instructions:

Using Rails, Thin and SSL in RubyMine: The solution!

Basically, you add foreman to your Gemfile:

gem 'foreman'

Then create a Procfile (the link misspells this) in your root containing this:

web: thin start --ssl

or, to bind to 0.0.0.0 as RubyMine usually does:

web: thin start -a 0.0.0.0 -p 3001 --ssl

I did not need to specify the location of my ssl files, but if you wanted to it would be:

web: thin start -a 0.0.0.0 -p 3001 --ssl --ssl-key-file /private/etc/apache2/ssl/server.key --ssl-cert-file /private/etc/apache2/ssl/server.crt

I would not recommend using --ssl-verify because that did not work for me.

Last, in RubyMine, create a new Ruby Configuration with the following attributes:

  • Ruby script: This should be the path to the foreman executable, e.g.: ~/.rvm/gems/ruby-2.3.0@gemset/gems/foreman-0.82.0/bin/foreman
  • Script arguments: start
  • Working directory: The root directory of your project, e.g. ~/Sites/appname

In the Bundler tab, check the only checkbox to use bundle exec when running it.

Last, in the logs tab, add a new log file pointing to ~/Sites/appname/logs/development.log

Allonge answered 13/1, 2017 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.