LearningWebAppDev
LearningWebAppDev copied to clipboard
Building the Server on page 205.
After adding the JSON file as a variable in the server.js of Amazeriffic, will there have to be any changes in the app.js file? I think the main method of app.js needs a toDoObjects to be passed to it, but the $document.ready(function () { ... requires a todos.json file. Which shouldn't be existing anymore since we've renamed it to todos.OLD.json on page 204. Will app.js still be called using the $.getJSON element?
$(document).ready(function () {
$.getJSON("todos.json", function (toDoObjects) {
// we'll call main with toDos as an argument
main(toDoObjects);
})
});
No, in this case, the todos.json
file will be dynamically generated on the request. Everything should still work, assuming your routes are set up correctly.
Are you hitting a problem?
On page 203, this is the DOM manipulation code I came up with. And it only prints tweetCounts to the DOM. Is that what the DOM should print? I was thinking it would print the stream to the DOM. If it will, how will I go about it?
var insertCountsIntoDOM = function (counts) {
// your DOM mainpulation code here
var $message = $("<p>").text(counts);
$("main .content").append($message);
};
On page 205, I've found out that the code won't work if I used curly braces in front of the variable toDos. I mean, doing this... toDos = { //Set up todo list here by copying.... It works with the angular brace. The one in the repository is correct, as it uses an angular bracket.
var express = require("express"),
http = require("http"),
app = express(),
toDos = [
// set up todo list here by copying
// the content from todos.OLD.json
]
toDos = { // it breaks!
// set up todo list here by copying
// the content from todos.OLD.json
};
app.use(express.static(__dirname + "/client"));
http.createServer(app).listen(3000);
// This route takes the place of our
// todos.json file in our example from
// Chapter 5
app.get("/todos.json", function (req, res) {
res.json(toDos);
});