Skip to content

Commit d90d36b

Browse files
committed
Clean up some code in the JS server, add comments
1 parent c0a9138 commit d90d36b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ app.set('port', (process.env.PORT || 3000));
2323
app.use('/', express.static(path.join(__dirname, 'public')));
2424
app.use(bodyParser.json());
2525
app.use(bodyParser.urlencoded({extended: true}));
26+
27+
// Additional middleware which will set headers that we need on each request.
2628
app.use(function(req, res, next) {
27-
//set permissive CORS header
29+
// Set permissive CORS header - this allows this server to be used only as
30+
// an API server in conjunction with something like webpack-dev-server.
2831
res.setHeader('Access-Control-Allow-Origin', '*');
32+
33+
// Disable caching so we'll always get the latest comments.
34+
res.setHeader('Cache-Control', 'no-cache');
2935
next();
3036
});
3137

@@ -35,7 +41,6 @@ app.get('/api/comments', function(req, res) {
3541
console.error(err);
3642
process.exit(1);
3743
}
38-
res.setHeader('Cache-Control', 'no-cache');
3944
res.json(JSON.parse(data));
4045
});
4146
});
@@ -61,7 +66,6 @@ app.post('/api/comments', function(req, res) {
6166
console.error(err);
6267
process.exit(1);
6368
}
64-
res.setHeader('Cache-Control', 'no-cache');
6569
res.json(comments);
6670
});
6771
});

0 commit comments

Comments
 (0)