简体   繁体   中英

Exclude list of words in Express.js route

I have something like this in Express.js Framework

app.post('/:username/:slug', user.fn);

Now I want to come up with a regular expression that checks if slug is equal to certain words (profile, album, etc.) , pass to the next route and don't capture the slug and username.

any ideas ?

You should just put the more specific routes first:

app.post('/:username/profile', middlware)
app.post('/:username/album', middleware)
app.post('/:username/:slug', middleware)

But then again, I don't know what you're trying to accomplish

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM