Skip to content

Commit

Permalink
Merge pull request #206 from mlibrary/rake_and_cors
Browse files Browse the repository at this point in the history
Rake and cors
  • Loading branch information
billdueber authored Sep 23, 2024
2 parents b9a9a71 + bed60d9 commit 387135c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ gem "aws-sdk-s3", "~> 1.160"
gem "content_disposition", "~> 1.0"
gem "uppy-s3_multipart", "~> 1.2"

# CORS
gem 'rack-cors'

#####################################
# Try to work around brokenness on
# nectar.
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ GEM
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.6.4)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rails (5.2.8.1)
Expand Down Expand Up @@ -479,6 +481,7 @@ DEPENDENCIES
pry-rails
puma (>= 4.3.5)
rack (>= 2.1.4)
rack-cors
rails (~> 5.0)
rake (~> 13.0)
rsolr (>= 1.0)
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"
resource '*', headers: :any, methods: [:get, :post]
end
end
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
Rails.application.routes.default_url_options ||= {}
Rails.application.routes.default_url_options[:script_name] = Dromedary::Services[:relative_url_root].chomp("/") + "/"

# Have to add when using X-Forwarded-Host and a relative URL. It's a hack.


if Dromedary::Services[:rails_url_host]
Rails.application.routes.default_url_options[:host] = Dromedary::Services[:rails_url_host]
end

Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

Expand Down
8 changes: 6 additions & 2 deletions lib/dromedary/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ module Dromedary
tmpdir
end

# The "live data dir" is no longer used for anything but holding onto the
# maintenance mode flag.
# Rack is suppsed to handle X-Forwarded-Host but seems to not do so. So, when we're
# running with the proxy handlers and don't explicitly set the path, it borks.

Services.register(:rails_url_host) { ENV["RAILS_URL_HOST"] || nil }



#### NAMING ####

Expand Down

0 comments on commit 387135c

Please sign in to comment.