Creating routes in Express.js from a JSON file with the specified structure:
{
"/home":{
"token":"ksdjfglkas"
},
"/logout":{
"token":"ksdjfglksaudhf"
}
}
It is necessary to access the token within the routes function. The JavaScript code used for generating the route is as follows:
for(var endpoint in context){
var route = context[endpoint];
app.use(endpoint,
function(req,res,next){
req.token= route.token;
next();
},
require('./route-mixin'));
}
The issue encountered is that the route-mixin method always receives the last token. In this case, 'context' refers to the JavaScript file mentioned above. How can different tokens be passed for each route individually.