The server code is very simple for this application. First, we need to render the index.ejs
template with the event models in the database. So, make sure our GET request catch-all looks like the following code:
app.get('/*', function (req, res) { db.find(function (err, events) { res.render("index.ejs", { events: JSON.stringify(events) }); }); });
Now, in the index.ejs
file of the views
folder, in the router creation code, remove the dummy records that we put in and replace it with the template data, like this:
calendar: new App.Models.Calendar(<%- events %>)
Back in the server.js
file, we need the route that the POST request is sent to when we're creating a new Event
model. Its code is as follows:
app.post('/events', function (req, res) { var b = req.body; db.insert({ title: b.title, date: b.date, startTime: b.startTime, endTime: b.endTime }, function (err, evt) { res.json(evt); -}); });