Skip to content

Commit

Permalink
[node] Use express's built-in json headers, set no cache on GET
Browse files Browse the repository at this point in the history
  • Loading branch information
zpao committed Jun 9, 2015
1 parent fef6397 commit 78c36e3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ app.use(bodyParser.urlencoded({extended: true}));

app.get('/comments.json', function(req, res) {
fs.readFile('comments.json', function(err, data) {
res.setHeader('Content-Type', 'application/json');
res.send(data);
res.setHeader('Cache-Control', 'no-cache');
res.json(JSON.parse(data));
});
});

Expand All @@ -34,9 +34,8 @@ app.post('/comments.json', function(req, res) {
var comments = JSON.parse(data);
comments.push(req.body);
fs.writeFile('comments.json', JSON.stringify(comments, null, 4), function(err) {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'no-cache');
res.send(JSON.stringify(comments));
res.json(comments);
});
});
});
Expand Down

0 comments on commit 78c36e3

Please sign in to comment.