Skip to content

Commit

Permalink
Simplified analysis_jobs routing
Browse files Browse the repository at this point in the history
Having the client and server both use the `/analysis_jobs` route was
nearly impossible to get working.

Instead, the client moved its UI to `/audio_analysis` in
QutEcoacoustics/baw-client@21b0fc8.

Also committing unit tests for the Rack::Rewrite rewrite rules which
were previously untested.
  • Loading branch information
atruskie committed Dec 1, 2016
1 parent 11d1abf commit 47f8fc2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
8 changes: 1 addition & 7 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions spec/routing/rack_rewrite_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 47f8fc2

Please sign in to comment.