[Git][noosfero/noosfero][master] api: ensure relative root is prefixed to the api path
Rodrigo Souto
gitlab at gitlab.com
Tue Sep 29 18:30:40 BRT 2015
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
014031e1 by Rodrigo Souto at 2015-09-29T18:28:48Z
api: ensure relative root is prefixed to the api path
- - - - -
3 changed files:
- app/views/api/playground.html.erb
- lib/noosfero/api/api.rb
- public/javascripts/api-playground.js
Changes:
=====================================
app/views/api/playground.html.erb
=====================================
--- a/app/views/api/playground.html.erb
+++ b/app/views/api/playground.html.erb
@@ -1,6 +1,8 @@
<h1>API Playground</h1>
<script>
+<% prefix = Noosfero::API::API.prefix %>
+var prefix = <%= prefix.to_json %>;
var endpoints = <%=
endpoints.map do |endpoint|
app = endpoint.options[:app].to_s
@@ -13,8 +15,8 @@ endpoints.map do |endpoint|
end
end
end.flatten.compact.sort{|a,b|
- a[:path]=='/api/v1/login' ? -1 :
- b[:path]=='/api/v1/login' ? 1 :
+ a[:path]=="#{prefix}/v1/login" ? -1 :
+ b[:path]=="#{prefix}/v1/login" ? 1 :
a[:path] <=> b[:path]
}.to_json %>;
</script>
@@ -33,4 +35,4 @@ end.flatten.compact.sort{|a,b|
</div>
<pre id="api-response" class="empty"></pre>
-<script src="/javascripts/api-playground.js"></script>
+<%= javascript_include_tag 'api-playground' %>
=====================================
lib/noosfero/api/api.rb
=====================================
--- a/lib/noosfero/api/api.rb
+++ b/lib/noosfero/api/api.rb
@@ -32,7 +32,7 @@ module Noosfero
after { set_session_cookie }
version 'v1'
- prefix "api"
+ prefix [ENV['RAILS_RELATIVE_URL_ROOT'], "api"].compact.join('/')
format :json
content_type :txt, "text/plain"
=====================================
public/javascripts/api-playground.js
=====================================
--- a/public/javascripts/api-playground.js
+++ b/public/javascripts/api-playground.js
@@ -24,7 +24,7 @@ var playground = {
selEndpoint: function() {
var endpoint = this.getEndpoint();
jQuery('#api-form .api-param').remove();
- if ( endpoint.path == '/api/v1/login' ) {
+ if ( endpoint.path == prefix+'/v1/login' ) {
this.addFormParam('login');
this.addFormParam('password');
}
@@ -51,7 +51,7 @@ var playground = {
for (var i=1; i<rawData.length; i+=2) {
data[ rawData[i].value ] = rawData[i+1].value;
}
- if ( endpoint.path != '/api/v1/login' ) {
+ if ( endpoint.path != prefix+'/v1/login' ) {
data.private_token = this.getToken();
}
jQuery('#api-response').empty()[0].className = 'empty';
@@ -71,7 +71,7 @@ var playground = {
jQuery('#api-response').text(
JSON.stringify(data, null, ' ')
)[0].className = 'full';
- if ( endpoint.path == '/api/v1/login' ) {
+ if ( endpoint.path == prefix+'/v1/login' ) {
playground.setToken(data.private_token)
}
},
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/014031e1f34ab5508ce9d9b421f8b98f517111c7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150929/bcb72f86/attachment-0001.html>
More information about the Noosfero-dev
mailing list