Override Radiant CMS's routes from the extension to set protocol to https

107 Views Asked by At

I am using a CMS called Radiant (version 0.9.1), Rails 2.3.18 and Ruby 1.8.7. I have to make the routes in this gem use the 'https'. I need to do it in such a way that I won't edit the gem source files itself, but rather override the gem's routes in the extension. How do I do this?

1

There are 1 best solutions below

2
Laurens On

The configuration of the server really depends on what your server stack looks like

To configure your rails application to use SSL you need to force ssl

In your config/environments/production.rb:

config.force_ssl = true

To test ssl locally I would suggest trying thin as a webserver (also put config.force_ssl in development.rb to test this )

Add:

gem 'thin' 

To your gemfile and start a thin ssl server:

$ thin start --ssl -p 3000

EDIT Rails 2 :

For Rails 2 this should work:

lib/force_ssl.rb

class ForceSSL
  def initialize(app)
    @app = app
  end

  def call(env)
    if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
      @app.call(env)
    else
      req = Rack::Request.new(env)
      [301, { "Location" => req.url.gsub(/^http:/, "https:") }, []]
    end
  end
end

config/production.rb

config.middleware.use "ForceSSL"

config/application.rb

require File.expand_path('../../lib/force_ssl.rb', __FILE__)

source: Force SSL using ssl_requirement in Rails 2 app