Merge pull request #117 from zach-chai/update_routes

Update routes to support relative root urls
This commit is contained in:
Zachary Chai 2017-02-07 14:49:23 -05:00 committed by GitHub
commit adb0314701
14 changed files with 50 additions and 37 deletions

View File

@ -26,8 +26,7 @@ class @Meeting
if _meetingInstance
return _meetingInstance
meetingId = $(".page-wrapper").data('id')
if (type = location.pathname.split('/')[1]) != 'rooms'
type = 'meetings'
type = $("body").data('resource')
name = $('.meeting-user-name').val()
adminId = $(".page-wrapper").data('admin-id')
_meetingInstance = new Meeting(meetingId, type, name, adminId)
@ -42,12 +41,14 @@ class @Meeting
fullId = encodeURIComponent(adminId) + '/' + encodeURIComponent(meetingId)
else
fullId = encodeURIComponent(meetingId)
return @buildFullDomainURL() + '/' + type + '/' + fullId
return @buildRootURL() + '/' + type + '/' + fullId
@buildFullDomainURL: ->
@buildRootURL: ->
url = location.protocol + '//' + location.hostname
if location.port
url += ':' + location.port
if GreenLight.relative_root
url += GreenLight.relative_root
return url
# Sends the end meeting request

View File

@ -238,7 +238,7 @@ class @Recordings
getRecordingsURL: ->
if $(".page-wrapper.rooms").data('main-room')
base_url = '/rooms/'+Meeting.getInstance().getAdminId()
base_url = Meeting.buildRootURL()+'/'+$('body').data('resource')+'/'+Meeting.getInstance().getAdminId()
else
base_url = $('.meeting-url').val()
base_url+'/recordings'

View File

@ -29,4 +29,9 @@ class ApplicationController < ActionController::Base
@current_user ||= User.find_by(id: session[:user_id])
end
helper_method :current_user
def relative_root
Rails.configuration.relative_url_root || ""
end
helper_method :relative_root
end

View File

@ -66,7 +66,7 @@ class BbbController < ApplicationController
}
end
base_url = "#{request.base_url}/#{params[:resource]}/#{meeting_path}"
base_url = "#{request.base_url}#{relative_root}/#{params[:resource]}/#{meeting_path}"
options[:meeting_logout_url] = base_url
options[:hook_url] = "#{base_url}/callback"

View File

@ -72,7 +72,9 @@ class LandingController < ApplicationController
return
end
@meeting_id = params[:id]
if @user.encrypted_id != params[:id]
@meeting_id = params[:id]
end
@meeting_running = bbb_get_meeting_info("#{@user.encrypted_id}-#{@meeting_id}")[:returncode]
@main_room = @meeting_id.blank? || @meeting_id == @user.encrypted_id

View File

@ -43,6 +43,10 @@ module ApplicationHelper
end
end
def omniauth_login_url(provider)
"#{relative_root}/auth/#{provider}"
end
# Whether the current page is the page of a room/meeting or not
def on_room_or_meeting_page?
params[:id].present?

View File

@ -44,7 +44,7 @@ class User < ApplicationRecord
end
def room_url
"/rooms/#{encrypted_id}"
"#{Rails.configuration.relative_url_root}/rooms/#{encrypted_id}"
end
def set_encrypted_id

View File

@ -38,7 +38,7 @@
<% else %>
<div class="text-center">
<div><%= t('are_you', name: @user.name) %></div>
<div class=""><%= link_to t('login'), '/users/login' %></div>
<div class=""><%= link_to t('login'), user_login_url %></div>
</div>
<% end %>
</div>

View File

@ -18,15 +18,15 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<head>
<title>Greenlight</title>
<%= csrf_meta_tags %>
<%= action_cable_meta_tag %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="action-cable-url" content="<%= relative_root+Rails.configuration.action_cable.mount_path %>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
</head>
<body class="app-background" data-controller="<%= params[:controller] %>" data-action="<%= params[:action] %>">
<body class="app-background" data-controller="<%= params[:controller] %>" data-action="<%= params[:action] %>" data-resource="<%= params[:resource] %>">
<!-- Messages -->
<div id='alerts'>
</div>
@ -53,6 +53,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
<script type="text/javascript">
window.I18n = <%= client_translations.to_json.html_safe %>
window.GreenLight = {};
window.GreenLight.relative_root = "<%= relative_root %>"
window.GreenLight.META_LISTED = "<%= BbbApi::META_LISTED %>";
window.GreenLight.META_TOKEN = "<%= BbbApi::META_TOKEN %>";
window.GreenLight.META_HOOK_URL = "<%= BbbApi::META_HOOK_URL %>";

View File

@ -26,7 +26,7 @@
<%= render layout: 'shared/center_panel' do %>
<div class="center-block center-panel-content-size col-xs-12">
<% if omniauth_providers_configured(:twitter) %>
<%= link_to '/auth/twitter', class: "signin-link signin-link-twitter" do %>
<%= link_to omniauth_login_url(:twitter), class: "signin-link signin-link-twitter" do %>
<div class="signin-button center-block">
<div class="signin-icon-wrapper">
<%= image_tag("twitter_signin_logo.png", alt: "T", class: "signin-icon") %>
@ -38,7 +38,7 @@
<% end %>
<% end %>
<% if omniauth_providers_configured(:google) %>
<%= link_to '/auth/google', class: "signin-link signin-link-google" do %>
<%= link_to omniauth_login_url(:google), class: "signin-link signin-link-google" do %>
<div class="signin-button center-block">
<div class="signin-icon-wrapper">
<%= image_tag("g-normal.png", alt: "G", class: "signin-icon") %>

View File

@ -26,7 +26,7 @@
<% else %>
<div class="text-center">
<span><%= t('login_description') %></span>
<div><%= link_to t('login'), '/users/login' %></div>
<div><%= link_to t('login'), user_login_url %></div>
</div>
<% end %>
</span>

View File

@ -2,4 +2,6 @@
require_relative 'config/environment'
run Rails.application
map Greenlight::Application.config.relative_url_root || "/" do
run Rails.application
end

View File

@ -19,7 +19,7 @@ Rails.application.routes.draw do
mount ActionCable.server => '/cable'
resources :users, only: [:edit, :update]
get '/users/login', to: 'sessions#new'
get '/users/login', to: 'sessions#new', as: :user_login
get '/users/logout', to: 'sessions#destroy', as: :user_logout
match '/auth/:provider/callback', to: 'sessions#create', via: [:get, :post]
@ -28,29 +28,25 @@ Rails.application.routes.draw do
# There are two resources [meetings|rooms]
# meetings offer a landing page for NON authenticated users to create and join session in BigBlueButton
# rooms offer a customized landing page for authenticated users to create and join session in BigBlueButton
scope '/:resource', constraints: {resource: /meetings|rooms/} do
# recording routes for updating, deleting and viewing recordings
get '/rooms/:room_id/recordings', to: 'bbb#recordings', defaults: {format: 'json'}
patch '/rooms/:room_id/recordings/:record_id', to: 'bbb#update_recordings', defaults: {format: 'json'}
delete '/rooms/:room_id/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {format: 'json'}
get '/rooms/:room_id/:id/recordings', to: 'bbb#recordings', defaults: {format: 'json'}
patch '/rooms/:room_id/:id/recordings/:record_id', to: 'bbb#update_recordings', defaults: {format: 'json'}
delete '/rooms/:room_id/:id/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {format: 'json'}
# room specific routes
scope '/:room_id' do
# recording routes for updating, deleting and viewing recordings
get '/(:id)/recordings', to: 'bbb#recordings', defaults: {id: nil, format: 'json'}
patch '/(:id)/recordings/:record_id', to: 'bbb#update_recordings', defaults: {id: nil, format: 'json'}
delete '/(:id)/recordings/:record_id', to: 'bbb#delete_recordings', defaults: {id: nil, format: 'json'}
# room routes for joining, ending, waiting and refreshing authenticated meetings
get '/rooms/:room_id', to: 'landing#resource', resource: 'rooms'
get '/rooms/:room_id/:id', to: 'landing#resource', resource: 'rooms'
get '/rooms/:room_id/:id/join', to: 'bbb#join', resource: 'rooms', defaults: {format: 'json'}
delete '/rooms/:room_id/:id/end', to: 'bbb#end', defaults: {format: 'json'}
# routes shared between meetings and rooms
get '/:resource/:id', to: 'landing#resource', as: :resource
get '/:resource/:id/join', to: 'bbb#join', as: :bbb_join, defaults: {format: 'json'}
post '/:resource/:id/callback', to: 'bbb#callback' #, defaults: {format: 'json'}
get '/:resource/:room_id/:id/wait', to: 'landing#wait_for_moderator'
get '/:resource/:room_id/:id/session_status_refresh', to: 'landing#session_status_refresh'
delete '/:id/end', to: 'bbb#end', defaults: {format: 'json'}
get '/:id/wait', to: 'landing#wait_for_moderator'
get '/:id/session_status_refresh', to: 'landing#session_status_refresh'
end
# routes shared between meetings and rooms
get '/(:room_id)/:id/join', to: 'bbb#join', defaults: {room_id: nil, format: 'json'}
get '/(:room_id)/:id', to: 'landing#resource', as: :meeting_room, defaults: {room_id: nil}
post '/:id/callback', to: 'bbb#callback' #, defaults: {format: 'json'}
end
root to: 'landing#index', :resource => 'meetings'
end

View File

@ -10,6 +10,8 @@ services:
- '.:/usr/src/app'
volumes_from:
- gem_cache
env_file:
- .env
expose:
- '3001'
stdin_open: true