Cheers! Ho negozio brace-dati:Ember.js ember-data restadapter non riesce a caricare json
TravelClient.Store = DS.Store.extend({
revision: 11,
adapter: DS.RESTAdapter.create({ bulkCommit: false, url: "http://someIP:somePORT"})
});
E router:
TravelClient.ToursRoute = Ember.Route.extend({
model: function() {
return TravelClient.Tour.find();
}
});
ricevo questo JSON dal server remoto:
{
"tours": [
{
"id": "5110e8b5a8fefe71e0000197",
"title": "qui deserunt dolores",
"description": "Id velit nihil.",
"seats": 12,
"options": [
],
"images": [
{
"id": "5110e8b5a8fefe71e0000196",
"url": "url"
}
}
Ma quando provo a return TravelClient.Tour.find()
non riesce con:
http://someIP:somePORT/tours 404 (Not Found)
XMLHttpRequest cannot load http://someIP:somePORT/tours. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.
Sembra che RESTAdapter non sappia, che debba ricevere JSON o cosa?
UPDATE:
Nel controllore dell'applicazione sulle rotaie sul lato server:
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
end
Ma è ancora:
OPTIONS http://someIP:somePORT/tours 404 (Not Found)
E sembra RESTAdapter tenta di caricare tour risorsa, non tours.json:
Request URL:http://someIP:somePORT/tours
LAVORO SOLUZIONE
Estendere RESTAdapter:
TravelClient.CUSTOMAdapter = DS.RESTAdapter.extend({
bulkCommit: false,
url: "http://remote_server_address",
buildURL: function(record, suffix) {
var s = this._super(record, suffix);
return s + ".json";
}
})
e rispondere a una richiesta OPTIONS con le intestazioni di destra
le intestazioni impostate vengono restituiti con il 'GET' richiesta è necessario restituirli con una richiesta OPTIONS' – albertjan
CORS Rack gemma' ha fatto il trucco, grazie. Penso che stia facendo tutte queste cose con le richieste di OPTIONS solo "out of the box". – xamenrax
Ecco il link per il prossimo visitatore https://github.com/cyu/rack-cors ftw – genkilabs