\$\begingroup\$
\$\endgroup\$
I have several routes, and I need Facebook authentication only in the routes that start with /admin
:
app.get('/admin/dashboard', passport.ensureAuthenticated, .....);
app.get('/admin/dashboard/new/email', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/question', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/answer', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/etc', passport.ensureAuthenticated, ....);
If I can't use the app.use
, is there anyone to call passport.ensureAuthenticated
repetition in routes that start with /admin
?
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Feb 2, 2015 at 16:13
user63272user63272
1 Answer 1
\$\begingroup\$
\$\endgroup\$
0
From Express docs:
Path
// will match paths starting with /abcd
app.use('/abcd', function (req, res, next) {
next();
})
Path Pattern
// will match paths starting with /abcd and /abd
app.use('/abc?d', function (req, res, next) {
next();
})
// will match paths starting with /abcd, /abbcd, /abbbbbcd and so on
app.use('/ab+cd', function (req, res, next) {
next();
})
// will match paths starting with /abcd, /abxcd, /abFOOcd, /abbArcd and so on
app.use('/ab*cd', function (req, res, next) {
next();
})
// will match paths starting with /ad and /abcd
app.use('/a(bc)?d', function (req, res, next) {
next();
})
Regular Expression
// will match paths starting with /abc and /xyz
app.use(/\/abc|\/xyz/, function (req, res, next) {
next();
})
Array
// will match paths starting with /abcd, /xyza, /lmn, and /pqr
app.use(['/abcd', '/xyza', /\/lmn|\/pqr/], function (req, res, next) {
next();
})
answered Feb 3, 2015 at 17:36
default