close #33 (site not found)
did
committed Mar 18, 2015
commit 44b787f8d3a799d6fa27b4768b19a24ce8654a80
Showing 5
changed files with
36 additions
and 5 deletions
bin/steam.rb
+0
-1
| @@ | @@ -75,7 +75,6 @@ Locomotive::Steam.configure do |config| |
| config.serve_assets = options[:asset_path].present? | |
| config.asset_path = options[:asset_path] | |
| config.asset_host = options[:asset_host] | |
| - | config.mounted_on = options[:mounted_on] |
| config.minify_assets = false | |
| end | |
locomotive/steam/middlewares/favicon.rb b/lib/locomotive/steam/middlewares/favicon.rb
+1
-1
| @@ | @@ -7,7 +7,7 @@ module Locomotive::Steam |
| def call(env) | |
| if env['PATH_INFO'] == '/favicon.ico' | |
| - | log 'Default and empty Favicon rendered' |
| + | # Default and empty Favicon rendered |
| [200, { 'Content-Type' => 'image/vnd.microsoft.icon' }, ['']] | |
| else | |
| app.call(env) | |
locomotive/steam/middlewares/site.rb b/lib/locomotive/steam/middlewares/site.rb
+28
-2
| @@ | @@ -1,13 +1,39 @@ |
| module Locomotive::Steam | |
| module Middlewares | |
| - | # Fetch a site using the site_finder service |
| + | # Fetch a site using the site_finder service. Look for an existing |
| + | # site in the rack env variable (context: when launched from the Engine). |
| # | |
| class Site < ThreadSafe | |
| + | include Helpers |
| + | |
| def _call | |
| env['steam.site'] ||= services.site_finder.find | |
| - | services.repositories.current_site = env['steam.site'] |
| + | services.repositories.current_site = site = env['steam.site'] |
| + | |
| + | # render a simple message if the service was not able to find a site |
| + | # based on the request. |
| + | render_no_site unless site |
| + | |
| + | # log anyway |
| + | log_site(site) |
| + | end |
| + | |
| + | private |
| + | |
| + | def render_no_site |
| + | render_response('Hi, we are sorry but no site was found.', 404, 'text/html') |
| + | end |
| + | |
| + | def log_site(site) |
| + | if site.nil? |
| + | msg = "Unable to find a site, url asked: #{request.url} ".colorize(color: :light_white, background: :red) |
| + | else |
| + | msg = site.name.colorize(color: :light_white, background: :blue) |
| + | end |
| + | |
| + | log msg, 0 |
| end | |
| end | |
locomotive/steam/server.rb b/lib/locomotive/steam/server.rb
+1
-1
| @@ | @@ -46,8 +46,8 @@ module Locomotive::Steam |
| def steam_middleware_stack | |
| [ | |
| Middlewares::DefaultEnv, | |
| - | Middlewares::Logging, |
| Middlewares::Site, | |
| + | Middlewares::Logging, |
| Middlewares::Timezone, | |
| Middlewares::EntrySubmission, | |
| Middlewares::Locale, | |
spec/integration/server/basic_spec.rb
+6
-0
| @@ | @@ -8,6 +8,12 @@ describe Locomotive::Steam::Server do |
| run_server | |
| end | |
| + | it 'displays an error message if the site does not exist' do |
| + | get '/index', {},{ 'HTTP_HOST' => 'www.nowhere.org/index' } |
| + | expect(last_response.status).to eq(404) |
| + | expect(last_response.body).to eq 'Hi, we are sorry but no site was found.' |
| + | end |
| + | |
| it 'shows the index page' do | |
| get '/index' | |
| expect(last_response.status).to eq(200) | |