From 4dbfdf30c3235eb19e4f0ad959f65125ed18b39a Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 8 Jul 2014 10:57:44 +0200 Subject: render valid json error if provider file not found --- app/controllers/static_config_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/static_config_controller.rb') diff --git a/app/controllers/static_config_controller.rb b/app/controllers/static_config_controller.rb index c669316..450cbb2 100644 --- a/app/controllers/static_config_controller.rb +++ b/app/controllers/static_config_controller.rb @@ -17,8 +17,8 @@ class StaticConfigController < ActionController::Base render :text => File.read(PROVIDER_JSON) end else - render :text => 'not found', :status => 404 + render json: {error: 'not found'}, status: 404 end end -end \ No newline at end of file +end -- cgit v1.2.3 From f07c952c870bfb8634ef0d80737b67a1eec760f6 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 14 Jul 2014 13:04:30 +0200 Subject: send config files from ConfigsController --- app/controllers/static_config_controller.rb | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'app/controllers/static_config_controller.rb') diff --git a/app/controllers/static_config_controller.rb b/app/controllers/static_config_controller.rb index 450cbb2..c78e006 100644 --- a/app/controllers/static_config_controller.rb +++ b/app/controllers/static_config_controller.rb @@ -2,23 +2,28 @@ # This controller is responsible for returning some static config files, such as /provider.json # class StaticConfigController < ActionController::Base + include ControllerExtension::JsonFile - PROVIDER_JSON = File.join(Rails.root, 'config', 'provider', 'provider.json') + before_filter :set_minimum_client_version + before_filter :set_filename + before_filter :fetch_file + + PROVIDER_JSON = Rails.root.join('config', 'provider', 'provider.json') - # - # return the provider.json, ensuring that the header X-Minimum-Client-Version is sent - # regardless if a 200 or 304 (not modified) response is sent. - # def provider - response.headers["X-Minimum-Client-Version"] = APP_CONFIG[:minimum_client_version].to_s - if File.exists?(PROVIDER_JSON) - if stale?(:last_modified => File.mtime(PROVIDER_JSON)) - response.content_type = 'application/json' - render :text => File.read(PROVIDER_JSON) - end - else - render json: {error: 'not found'}, status: 404 - end + send_file end + protected + + # ensure that the header X-Minimum-Client-Version is sent + # regardless if a 200 or 304 (not modified) or 404 response is sent. + def set_minimum_client_version + response.headers["X-Minimum-Client-Version"] = + APP_CONFIG[:minimum_client_version].to_s + end + + def set_filename + @filename = PROVIDER_JSON + end end -- cgit v1.2.3