Skip to content

Commit 37d2647

Browse files
committed
fix favicon-related bug
1 parent 2a00da2 commit 37d2647

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/cookie-sessions/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ app.use(cookieSession({ secret: 'manny is cool' }));
1616
app.use(count);
1717

1818
// custom middleware
19-
function count(req, res) {
20-
req.session.count = (req.session.count || 0) + 1
21-
res.send('viewed ' + req.session.count + ' times\n')
19+
function count(req, res, next) {
20+
// without this check, a request to /favicon that
21+
// is made by most browsers will also increment the counter
22+
if (req.path.startsWith('/favicon.ico')) {
23+
return next();
24+
} else {
25+
req.session.count = (req.session.count || 0) + 1;
26+
res.send('viewed ' + req.session.count + ' times\n');
27+
}
2228
}
2329

2430
/* istanbul ignore next */

0 commit comments

Comments
 (0)