localhost
A bit about me |
|
Jeremy Greendrummer, coder, entrepreneur, photographer, brewerorganizer of OkcRuby.org |
|
@jagthedrummer jeremy@octolabs.com http://www.octolabs.com/ |
Start a local service
$ rails -p 3007
Configure Ember Data
// Configure Ember Data
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://localhost:3007'
});
$ export FILE_SERVICE=http://localhost:3007/
// Configure Ember Data
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: '<%= ENV["FILE_SERVICE"]%>',
namespace: 'api/v1'
});
App = Ember.Application.create({
ready: function(){
var store = App.__container__.lookup('store:main');
var id = 'me?_=' + (new Date()).getTime();
store.find('user',id).then(function(user){
App.currentUser = user;
});
}
});
401
error handler
App.ApplicationAdapter = DS.RESTAdapter.extend({
ajaxError: function(jqXHR) {
var error = this._super(jqXHR);
if (jqXHR && jqXHR.status === 401) {
var newLocation = "http://files.cloudhdr.com/auth?return=";
newLocation += encodeURIComponent(document.location.toString());
document.location = newLocation;
} else {
return error;
}
}
});
localhost
localhost
200 OK
on the server
# Gemfile
gem "rack-cors", :require => "rack/cors"
# config/application.rb
config.middleware.use Rack::Cors do
allow do
origins(/http:\/\/localhost:\d*/,
/https:\/\/cloudhdr-\w*-octolabs\.fwd\.wf/,
/http:\/\/[\w-]*\.cloudhdr\.com/
)
resource '/api/v1/*',
:headers => :any,
:methods => [:get, :post, :put, :delete, :options]
end
end
# config/application.rb
config.middleware.use Rack::Cors do
allow do
origins('*')
resource '/api/public/v1/*',
:headers => :any,
:methods => [:get]
end
end
# config/application.rb
config.middleware.use Rack::Cors do
allow do
origins('*')
resource '*',
:headers => :any,
:methods => [:get, :post, :put, :delete, :options]
end
end
withCredentials
to the rescue!
// send cookies with AJAX requests
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
options.xhrFields = { withCredentials : true };
});
@jagthedrummer jeremy@octolabs.com |