Skip to content

Commit

Permalink
Clean up some code in the JS server, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zpao committed Jan 26, 2016
1 parent c0a9138 commit d90d36b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ app.set('port', (process.env.PORT || 3000));
app.use('/', express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

// Additional middleware which will set headers that we need on each request.
app.use(function(req, res, next) {
//set permissive CORS header
// Set permissive CORS header - this allows this server to be used only as
// an API server in conjunction with something like webpack-dev-server.
res.setHeader('Access-Control-Allow-Origin', '*');

// Disable caching so we'll always get the latest comments.
res.setHeader('Cache-Control', 'no-cache');
next();
});

Expand All @@ -35,7 +41,6 @@ app.get('/api/comments', function(req, res) {
console.error(err);
process.exit(1);
}
res.setHeader('Cache-Control', 'no-cache');
res.json(JSON.parse(data));
});
});
Expand All @@ -61,7 +66,6 @@ app.post('/api/comments', function(req, res) {
console.error(err);
process.exit(1);
}
res.setHeader('Cache-Control', 'no-cache');
res.json(comments);
});
});
Expand Down

0 comments on commit d90d36b

Please sign in to comment.