Skip to content

Instantly share code, notes, and snippets.

@joshmn
Created September 28, 2018 21:48
Show Gist options
  • Save joshmn/1317d2ccf0c22f33d2074585a943a4a8 to your computer and use it in GitHub Desktop.
Save joshmn/1317d2ccf0c22f33d2074585a943a4a8 to your computer and use it in GitHub Desktop.
actual routes
class SiteConstraint
def matches?(request)
request.subdomain != 'my' && request.domain != 'localhost'
end
end
class AppConstraint
def matches?(request)
request.subdomain === 'my' || request.domain == 'localhost'
end
end
class ShortUrlConstraint
def matches?(request)
request.domain == 'tnvm.io' || request.raw_host_with_port == 'tnvm.lvh.me:3000'
end
end
Rails.application.routes.draw do
constraints ShortUrlConstraint.new do
get '*unmatched_route', to: redirect('https://my.tinyvoicemail.com/')
end
constraints SiteConstraint.new do
root :to => 'site/pages#root'
get '/developers' => 'site/pages#developers'
get '/swagger' => redirect("https://my.tinyvoicemail.com/swagger")
get '/instructions' => 'site/pages#instructions'
get '/faq' => 'site/pages#faq'
get '/terms' => 'site/pages#tos'
get '/tos' => 'site/pages#tos'
get '/privacy' => 'site/pages#privacy'
end
constraints AppConstraint.new do
resources :messages
mount API => '/'
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
root to: 'pages#root'
end
if Rails.env.production?
get '*unmatched_route', to: 'application#route_not_found', constraints: lambda { |req|
req.path.exclude? 'rails/active_storage'
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment