I\'m using Express 4 where I have a route protected by passport.js, like this:
var media = require(\'express\').Router();
media.get(\'/\', function(req, res) {
You could split your router up into protected/unprotected and call the middleware on the protected routes.
var express = require('express'),
media = express.Router(),
mediaProtected = express.Router();
media.get('/', function(req, res) {
// provide results from db
});
mediaProtected.post('/', function(req, res) {
// This route is auth protected
});
module.exports = {
protected: mediaProtected,
unprotected: media
};
And then you can do
var router = require('./my-router');
app.use('/api/route', passport.authenticate('bearer'), router.protected);
app.use('/api/route', router.unprotected);