mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Added subdomain based routing constraints
Non-wopi routes will only work with the subdomain set by the env variable USER_SUBDOMAIN (if it is set). Likewise, wopi routes will only work with the WOPI_SUBDOMAIN if it is set, but they also require the WOPI_ENABLED to be true.
This commit is contained in:
parent
1f67aec258
commit
495c648f41
2 changed files with 31 additions and 0 deletions
23
app/utilities/subdomain.rb
Normal file
23
app/utilities/subdomain.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class UserSubdomain
|
||||
def self.matches?(request)
|
||||
if ENV['USER_SUBDOMAIN']
|
||||
return request.subdomain.present? && request.subdomain = ENV['USER_SUBDOMAIN']
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class WopiSubdomain
|
||||
def self.matches?(request)
|
||||
if ENV['WOPI_ENABLED'] == "true"
|
||||
if ENV['WOPI_SUBDOMAIN']
|
||||
return request.subdomain.present? && request.subdomain = ENV['WOPI_SUBDOMAIN']
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,8 @@
|
|||
Rails.application.routes.draw do
|
||||
|
||||
require 'subdomain'
|
||||
|
||||
constraints (UserSubdomain) do
|
||||
devise_for :users, controllers: { registrations: "users/registrations",
|
||||
sessions: "users/sessions", invitations: "users/invitations",
|
||||
confirmations: "users/confirmations" }
|
||||
|
@ -266,10 +270,14 @@ Rails.application.routes.draw do
|
|||
post 'avatar_signature' => 'users/registrations#signature'
|
||||
end
|
||||
|
||||
end
|
||||
constraints (WopiSubdomain) do
|
||||
|
||||
# Office integration
|
||||
get 'wopi/files/:id/contents', to: 'wopi#file_contents_get_endpoint'
|
||||
post 'wopi/files/:id/contents', to: 'wopi#file_contents_post_endpoint'
|
||||
|
||||
get 'wopi/files/:id', to: 'wopi#file_get_endpoint', as: 'wopi_rest_endpoint'
|
||||
post 'wopi/files/:id', to: 'wopi#post_file_endpoint'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue