Skip to content

Commit

Permalink
fix favicon-related bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Kondar committed Jan 27, 2024
1 parent 2a00da2 commit 37d2647
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/cookie-sessions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ app.use(cookieSession({ secret: 'manny is cool' }));
app.use(count);

// custom middleware
function count(req, res) {
req.session.count = (req.session.count || 0) + 1
res.send('viewed ' + req.session.count + ' times\n')
function count(req, res, next) {
// without this check, a request to /favicon that
// is made by most browsers will also increment the counter
if (req.path.startsWith('/favicon.ico')) {
return next();
} else {
req.session.count = (req.session.count || 0) + 1;
res.send('viewed ' + req.session.count + ' times\n');
}
}

/* istanbul ignore next */
Expand Down

0 comments on commit 37d2647

Please sign in to comment.