Ho un middleware di autenticazione che deve effettuare una chiamata a un servizio esterno e fornire un URL di richiamata. Per esempio:È possibile ottenere l'URL di base per un router express
var express = require('express');
var app = express();
// This will work just fine
app.use('/', getAuthRouter());
// The redirects here will end up going to /oauth/callback
// instead of /admin/oauth/callback
app.use('/admin', getAuthRouter());
function getAuthRouter() {
var authRouter = express.Router();
// Setup auth routes
var callbackUrl = '/oauth/callback';
var loginUrl = '/login';
authRouter.get(callbackUrl, .... });
authRouter.get(loginUrl, function(req, res, next){
// Make call to OAuth server
res.redirect("http://authserver/?callback=" + callbackUrl);
});
return authRouter;
}
Il problema è che authRouter
non sa che in realtà è montato sotto /admin
quindi non ha modo di anteporre che al callback
param.
C'è un modo che posso ottenere che all'interno della funzione getAuthRouter
?
È interessante notare che esiste un "app.mountpath" che può essere eseguito, ma solo se si monta un'app secondaria e non un router. Ciò accade a destra [qui] (https://github.com/strongloop/express/blob/master/lib/application.js#L214-L221) – Fotios