diff --git a/config/application.rb b/config/application.rb index 79fe27f7..5df0d77b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -137,12 +137,6 @@ class Application < Rails::Application # for generating documentation from tests Raddocs.configuration.docs_dir = "doc/api" - def should_route_to_client(rack_env) - (rack_env['REQUEST_METHOD'] == 'GET' && - !(Mime::Type.parse(rack_env['HTTP_ACCEPT'] || '')).include?(Mime::JSON) && - File.extname(rack_env['REQUEST_PATH'] || '') == '') - end - # middleware to rewrite angular urls # insert at the start of the Rack stack. config.middleware.insert_before 0, Rack::Rewrite do @@ -153,7 +147,7 @@ def should_route_to_client(rack_env) rewrite /^\/library.*/i, '/listen_to/index.html' rewrite /^\/demo.*/i, '/listen_to/index.html' rewrite /^\/visualize.*/i, '/listen_to/index.html' - rewrite /^\/analysis_jobs.*/i, '/listen_to/index.html', if: Application.method(:should_route_to_client) + rewrite /^\/audio_analysis.*/i, '/listen_to/index.html' end # allow any origin, with any header, to access the array of methods diff --git a/spec/routing/rack_rewrite_spec.rb b/spec/routing/rack_rewrite_spec.rb new file mode 100644 index 00000000..6731cab7 --- /dev/null +++ b/spec/routing/rack_rewrite_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +describe 'Rack rewrite', :type => :feature do # :type => :routing + describe :routing do + + client_app_content = 'Client application placeholder This is the page that will be rendered if a client side view needs to be rendered.' + + it { + visit '/listen' + expect(page.text).to include(client_app_content) + } + + it { + visit '/birdwalks' + expect(page.text).to include(client_app_content) + } + + it { + visit '/library' + expect(page.text).to include(client_app_content) + } + + it { + visit '/demo' + expect(page.text).to include(client_app_content) + } + + it { + visit '/visualize' + expect(page.text).to include(client_app_content) + } + + it { + visit '/audio_analysis' + expect(page.text).to include(client_app_content) + } + + end +end \ No newline at end of file