I have the sample "todo" ember application working with LSAdapter; now i'm attempting to use the RESTAdapter and get the json data from node js;
In the Ember application i've done:
Todos.Store = DS.Store.extend({
revision: 13,
url: "http://127.0.0.1"
});
Todos.Todo = DS.Model.extend({
title: DS.attr('string'),
isCompleted: DS.attr('boolean')
});
And this is the main route handler:
Todos.TodosIndexRoute = Ember.Route.extend({
model: function() {
return Todos.Todo.find();
}
});
In ember data documentation they say that this should send an http request GET to url/todos, so in this case to:
http://127.0.0.1/todos
So i've made a Server with node js:
dispatcher.onGet("/todos", function(req, res) {
bind.toFile('tmpl/todos.tpl', {
id: "1",
title: 'Just a try',
is_completed: "false"
}, function(data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
});
});
It uses httpdispatcher and bind modules from npm, and works because if i type in the browser:
//url in the browser
127.0.0.1/todos
i get:
{ "todo": { "id": 1, "title": Just a try, "is_completed": false } }
But if i execute the app in the browser (URL: file:///D:/Works/Web%20Resources/EMBER%20MVC%20FRAMEWORK/Prova_App/index.html) the todo "Just a try" is not loaded; inspecting with chrome, in the console tab, i can read an error that says "Failed to load resource file:///D:/todos"
Can someone help to figure this out?
Why are you using a file:///? You need to request the page via the server.
When ember looks for the todos its checking the root of the domain. When requesting via a web address that is [address]/todos. When you use a file:/// request that becomes file:///D:/todos.