Revision 2b8cdec1
Added by Oved Ourfali over 11 years ago
- ID 2b8cdec1463d5abae58ae82ad8cc1a617b79beb9
Gemfile | ||
---|---|---|
require 'config/settings'
|
||
source 'http://rubygems.org'
|
||
|
||
gem 'rails', '3.0.17'
|
bundler.d/jsonp.rb | ||
---|---|---|
group :jsonp do
|
||
gem 'rack-jsonp', :require => 'rack/jsonp'
|
||
end if SETTINGS[:support_jsonp]
|
config/application.rb | ||
---|---|---|
require File.expand_path('../../lib/timed_cached_store.rb', __FILE__)
|
||
require File.expand_path('../../lib/core_extensions', __FILE__)
|
||
|
||
Bundler.require(:jsonp) if SETTINGS[:support_jsonp]
|
||
|
||
module Foreman
|
||
class Application < Rails::Application
|
||
# Setup additional routes by loading all routes file from routes directory
|
||
... | ... | |
# enables in memory cache store with ttl
|
||
#config.cache_store = TimedCachedStore.new
|
||
config.cache_store = :file_store, Rails.root.join("tmp")
|
||
|
||
# enables JSONP support in the Rack middleware
|
||
config.middleware.use Rack::JSONP if SETTINGS[:support_jsonp]
|
||
end
|
||
|
||
def self.setup_console
|
config/boot.rb | ||
---|---|---|
require 'rubygems'
|
||
require 'yaml'
|
||
|
||
root = File.expand_path(File.dirname(__FILE__) + "/..")
|
||
SETTINGS = YAML.load_file("#{root}/config/settings.yaml")
|
||
SETTINGS[:version] = File.read(root + "/VERSION").chomp rescue ("N/A")
|
||
SETTINGS[:unattended] = SETTINGS[:unattended].nil? || SETTINGS[:unattended]
|
||
SETTINGS[:login] ||= SETTINGS[:ldap]
|
||
require 'config/settings'
|
||
|
||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||
|
config/settings.rb | ||
---|---|---|
root = File.expand_path(File.dirname(__FILE__) + "/..")
|
||
SETTINGS = YAML.load_file("#{root}/config/settings.yaml")
|
||
SETTINGS[:version] = File.read(root + "/VERSION").chomp rescue ("N/A")
|
||
SETTINGS[:unattended] = SETTINGS[:unattended].nil? || SETTINGS[:unattended]
|
||
SETTINGS[:login] ||= SETTINGS[:ldap]
|
config/settings.yaml.example | ||
---|---|---|
:unattended: true
|
||
:login: false
|
||
:require_ssl: false
|
||
#JSONP or "JSON with padding" is a complement to the base JSON data format.
|
||
#It provides a method to request JSON data from a server in a different domain.
|
||
:support_jsonp: false
|
Also available in: Unified diff
fixes #1961 Adding JSONP support
When using cross-domain requests, it is impossible to read the response
data, and process it.
Using JSONP allows a client, from a specific domain (for example
/domain1), to query data in another doamin (/domain2), and analyze it,
using a callback.
Such a request would be followed by "callback=" parameter. For example:
http://foreman-server:3000/statistics?format=json&callback=analyzeStats
And the response would be:
analyzeStats({"statistics":{"mem_totfree":0.0,"arch_count":{},
"env_count":{},"cpu_count":{},"mem_size":0,"swap_size":0,
"model_count":{},"mem_free":0,"swap_free":0,"klass_count":{},
"os_count":{},"mem_totsize":0.0}})
which will call the analyzeStats callback.
Whereas a regular request,
http://foreman-server:3000/statistics?format=json, will just contain the
JSON data.
More reading on JSONP:
JSONP - http://en.wikipedia.org/wiki/JSONP
JSONP Ruby impl -
www.simb.net/2012/02/06/ruby-and-jsonp
https://github.com/crohr/rack-jsonp/