Quantcast
Channel: User Thomas - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Use specific middleware in Express for all paths except a specific one

$
0
0

I am using the Express framework in node.js with some middleware functions:

var app = express.createServer(options);app.use(User.checkUser);

I can use the .use function with an additional parameter to use this middleware only on specific paths:

app.use('/userdata', User.checkUser);

Is it possible to use the path variable so that the middleware is used for all paths except a specific one, i.e. the root path?

I am thinking about something like this:

app.use('!/', User.checkUser);

So User.checkUser is always called except for the root path.


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>