summaryrefslogtreecommitdiff
path: root/app/controllers/static_config_controller.rb
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-07-17 12:16:07 +0200
committerazul <azul@leap.se>2014-07-17 12:16:07 +0200
commitade74d8a9091ae607586d7b287a0579a2ee7af8e (patch)
tree74273b8ba7e35d0fb3c96aa79e63c93086d15146 /app/controllers/static_config_controller.rb
parent952bc18e8333ca5c3e6e16f8059f84a1414d5f6f (diff)
parente86cccb4b89540f3bd403110d051b2723be781b9 (diff)
Merge pull request #176 from azul/feature/api-authenticated-configs
API: Authenticated access to config settings
Diffstat (limited to 'app/controllers/static_config_controller.rb')
-rw-r--r--app/controllers/static_config_controller.rb35
1 files changed, 20 insertions, 15 deletions
diff --git a/app/controllers/static_config_controller.rb b/app/controllers/static_config_controller.rb
index c669316..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 :text => 'not found', :status => 404
- end
+ send_file
end
-end \ No newline at end of file
+ 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