Ask Your Question
1

Is it possible to prevent Nodejs express session from loading session for static content?

asked 2021-05-01 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-04-06 23:00:00 +0000

djk gravatar image

Yes, it is possible to prevent Nodejs express session from loading session for static content by using a middleware to check the request path and skipping the session middleware if the request is for static content. For example:

app.use((req, res, next) => {
  if (req.path.startsWith('/static')) {
    return next();
  }
  return sessionMiddleware(req, res, next);
});

In this example, the middleware checks if the request path starts with '/static'. If it does, it skips the session middleware and passes the request to the next middleware. If not, it calls the session middleware as usual.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-01 11:00:00 +0000

Seen: 11 times

Last updated: Apr 06 '23