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.
Asked: 2021-05-01 11:00:00 +0000
Seen: 12 times
Last updated: Apr 06 '23