【问题标题】:Only matching GET and POST routes if a static file doesn't match?如果静态文件不匹配,则仅匹配 GET 和 POST 路由?
【发布时间】:2012-02-03 04:32:47
【问题描述】:

我有这条路线: app.get('/:a/:b/:c', routes.get);

还有这个静态定义:

app.use('/test', express.static(__dirname + '/test')); 

现在,当我尝试访问/test/a/b.js 时出现问题。由于它匹配两个路径,routes.get 被触发。我该如何防止这种情况,并且仅在无法提供静态资源文件时才路由?

【问题讨论】:

    标签: javascript node.js express


    【解决方案1】:

    app.use(express.static(__dirname + '/test')) 放在app.use(app.router) 之前。

    中间件按照.configure() 中定义的顺序运行。

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 2018-11-21
      相关资源
      最近更新 更多