I'm trying to understand the order of execution, but everything is somehow confusing:
var ua = 'foo'; app.use(function(req, res, next){ ua = 'barr'; next(); }); app.use( session({ key: ua, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) ); as I understand it, middleware are executed in order (top-down), and in theory, the variable ua should be assigned the value bar , but this does not happen. explain why?
PS created an intermediate handler, because you need to assign a value from req for sessions
Is there a difference between the challenges:
app.use(function(req, res, next){ session({ key: key, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) next(); }); # и app.use( session({ key: key, secret: 'session_cookie_secret', store: sessionStore, resave: true, saveUninitialized: true }) );
{ key: ua,stringua = 'barr';- Grundysessionfunction is executed and the parameter for it is calculated - Grundyеще не выполнилась строка- isn’t everything supposed to be done in order? first the value of the variable is assigned, then the nextmiddlewareis executed - where thesessionis called - monsiureapp.use( session({arguments for the session are not calculated inside the middleware. - Grundy