more CORS docs

This commit is contained in:
Konstantin Haase 2012-09-20 14:43:15 +02:00
parent ddf404416e
commit da4f05901f
2 changed files with 21 additions and 6 deletions

View File

@ -9,7 +9,18 @@ reason for using JSONP, we recommend you use CORS.
## Cross-Origin Resource Sharing
... some general docs here ...
All API resources set appropriate headers to allow Cross-Origin requests. Be
aware that on Internet Explorer you might have to use a different interface to
send these requests.
// using XMLHttpRequest or XDomainRequest to send an API request
var invocation = window.XDomainRequest ? new XDomainRequest() : new XMLHttpRequest();
if(invocation) {
invocation.open("GET", "https://api.travis-ci.org/", true);
invocation.onreadystatechange = function() { alert("it worked!") };
invocation.send();
}
In contrast to JSONP, CORS does not lead to any execution of untrusted code.

View File

@ -38,14 +38,18 @@ class Travis::Api::App
end
def docs_for(entry)
markdown(entry['doc']).
gsub('<pre', '<pre class="prettyprint linenums lang-js pre-scrollable"').
gsub(/<\/?code>/, '').
gsub(/TODO:?/, '<span class="label label-warning">TODO</span>')
with_code_highlighting markdown(entry['doc'])
end
private
def with_code_highlighting(str)
str.
gsub('<pre', '<pre class="prettyprint linenums lang-js pre-scrollable"').
gsub(/<\/?code>/, '').
gsub(/TODO:?/, '<span class="label label-warning">TODO</span>')
end
def general_docs
@@general_docs ||= doc_files.map do |file|
header, content = File.read(file).split("\n", 2)
@ -58,7 +62,7 @@ class Travis::Api::App
end
header.gsub! /^#* */, ''
{ id: header, title: header, content: content, subheaders: subheaders }
{ id: header, title: header, content: with_code_highlighting(content), subheaders: subheaders }
end
end