如何在除静态资产之外的所有路由上运行中间件

除了静态资产,有没有办法在所有快速路线上运行中间件?

我试着在app.use('/', authenticate, app.router());运行它app.use('/', authenticate, app.router()); 但导致它运行的所有静态资产以及。

我只需要把它列在我的所有路线上?

正如@Explosion Pills在评论中指出的那样,

express.static中间件之后添加你的中间件

示例代码如下

 app.use('/', express.static(path.resolve(root, './build/client'))); app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true}); // ... app.use('/', authenticate, app.router());