lib/exvo_helpers/helpers.rb in exvo_helpers-0.0.8 vs lib/exvo_helpers/helpers.rb in exvo_helpers-0.1.0
- old
+ new
@@ -3,20 +3,28 @@
module Helpers
# Dynamically define class methods
class << self
- %w(cdn cfs desktop themes blog contacts inbox music pics preview).each do |service|
+ %w(auth cdn cfs desktop themes blog contacts inbox music pics preview).each do |service|
# def self.cdn_uri
- # protocol = ["cdn", "cfs", "themes"].include?(service) && env.to_sym == :production ? "//" : "http://"
+ # protocol = 'http://'
+ # protocol = 'https://' if service == "auth" && auth_require_ssl
+ # protocol = '//' if ["cdn", "cfs", "themes"].include?(service) && env.to_sym == :production
# protocol + cdn_host
# end
define_method "#{service}_uri" do
+ protocol = 'http://'
+
+ # explicit https for auth
+ protocol = 'https://' if service == "auth" && send(:auth_require_ssl)
+
# special link starting with '//' in production so that the webserver can choose between HTTP and HTTPS
# but only for those apps/services that have proper SSL support (i.e. valid certificates)
- protocol = ["cdn", "cfs", "themes"].include?(service) && env.to_sym == :production ? "//" : "http://"
+ protocol = '//' if ["cdn", "cfs", "themes"].include?(service) && env.to_sym == :production
+
protocol + send("#{service}_host")
end
# def self.cdn_host
# @@cdn_host ||= ENV['CDN_HOST'] || default_opts[env.to_sym][:cdn_host]
@@ -43,25 +51,17 @@
end
# AUTH
- # pass-in to the ExvoAuth gem
- def self.auth_uri
- if defined?(ExvoAuth::Config) and ExvoAuth::Config.respond_to?('uri')
- ExvoAuth::Config.uri
- else
- raise "Exvo.auth_uri method is available only when exvo-auth gem is available"
- end
+ def self.auth_require_ssl
+ return @@auth_require_ssl if defined?(@@auth_require_ssl) && !@@auth_require_ssl.nil?
+ @@auth_require_ssl = (ENV['AUTH_REQUIRE_SSL'] == 'true') || default_opts[env.to_sym][:auth_require_ssl]
end
- def self.auth_host
- if defined?(ExvoAuth::Config) and ExvoAuth::Config.respond_to?('host')
- ExvoAuth::Config.host
- else
- raise "Exvo.auth_host method is available only when exvo-auth gem is available"
- end
+ def self.auth_require_ssl=(require_ssl)
+ @@auth_require_ssl = require_ssl
end
# ENV
@@ -79,10 +79,12 @@
private
def self.default_opts
{
:production => {
+ :auth_host => 'auth.exvo.com',
+ :auth_require_ssl => true,
:cdn_host => 'd33gjlr95u9pgf.cloudfront.net', # cloudfront.net so we can use https (cdn.exvo.com via https does not work properly)
:cfs_host => 'cfs.exvo.com',
:desktop_host => 'www.exvo.com',
:themes_host => 'themes.exvo.com',
:blog_host => 'blog.exvo.com',
@@ -91,10 +93,12 @@
:music_host => 'music.exvo.com',
:pics_host => 'pics.exvo.com',
:preview_host => 'preview.exvo.com'
},
:staging => {
+ :auth_host => 'staging.auth.exvo.com',
+ :auth_require_ssl => false,
:cdn_host => 'd1by559a994699.cloudfront.net',
:cfs_host => 'staging.cfs.exvo.com',
:desktop_host => 'www.exvo.co',
:themes_host => 'staging.themes.exvo.com',
:blog_host => 'staging.blog.exvo.com',
@@ -103,10 +107,12 @@
:music_host => 'exvo-music-staging.heroku.com',
:pics_host => 'exvo-pictures-staging.heroku.com',
:preview_host => 'staging.preview.exvo.com'
},
:development => {
+ :auth_host => 'auth.exvo.local',
+ :auth_require_ssl => false,
:cdn_host => 'www.exvo.local',
:cfs_host => 'cfs.exvo.local',
:desktop_host => 'www.exvo.local',
:themes_host => 'themes.exvo.local',
:blog_host => 'blog.exvo.local',
@@ -115,9 +121,11 @@
:music_host => 'music.exvo.local',
:pics_host => 'pics.exvo.local',
:preview_host => 'preview.exvo.local'
},
:test => {
+ :auth_host => 'auth.exvo.local',
+ :auth_require_ssl => false,
:cdn_host => 'www.exvo.local',
:cfs_host => 'cfs.exvo.local',
:desktop_host => 'www.exvo.local',
:themes_host => 'themes.exvo.local',
:blog_host => 'blog.exvo.local',