expressjs绑定除2个文件夹以外的所有路由吗? [英] expressjs bind all routes except 2 folders?

查看:39
本文介绍了expressjs绑定除2个文件夹以外的所有路由吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在expressjs中,如何将路由绑定到除/static和/fail之外的所有URL

In expressjs, how do I bind a route to all urls except /static and /fail

例如,它听起来绑定到:

For example, it sound bind to:

/users
/books
/books/anything

但不绑定

/static
/fail
/fail/anything
/static/anything

推荐答案

如果您说要为/static *以外的所有内容创建一条路由,那么以下是用于创建GET路由的命令:

If you are saying you want to create one route for everything but /static* then here is the command for creating the GET route:

app.get(/^((?!\/static).)*$/, function(req, res){

    //Do your thing in here...
});

这篇关于expressjs绑定除2个文件夹以外的所有路由吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆