From f619178085d0c2729e275fa4f46f9cd981189d3e Mon Sep 17 00:00:00 2001 From: elijah Date: Sun, 29 Dec 2013 19:25:05 -0800 Subject: Return 'provider.json' via a controller, to better be able to control the response headers (in particular, 'X-Minimum-Client-Version'). It must now be placed in config/provider/provider.json --- app/controllers/static_config_controller.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/controllers/static_config_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/static_config_controller.rb b/app/controllers/static_config_controller.rb new file mode 100644 index 0000000..c669316 --- /dev/null +++ b/app/controllers/static_config_controller.rb @@ -0,0 +1,24 @@ +# +# This controller is responsible for returning some static config files, such as /provider.json +# +class StaticConfigController < ActionController::Base + + PROVIDER_JSON = File.join(Rails.root, '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 + end + +end \ No newline at end of file -- cgit v1.2.3