【问题标题】:express 3 routes being called unnecessarily快递 3 条路线被不必要地调用
【发布时间】:2013-08-09 18:17:25
【问题描述】:

我有 2 个路由,第一个用于 API,第二个是显示 html 页面的全部捕获。现在,即使我通过浏览器向 .../api/... 发出请求,并看到“无效” - 第二条路线,即“不必要地调用”仍然会被执行。我很困惑为什么要调用第二条路线,因为它已经通过了第一条路线。

// api route
app.get("/api/appname/stuff_settings/:setting", function(req, res) {
   // do api stuff
   res.send(500, 'Invalid');
});

app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');

// catch all route
app.use(express.static(path.join(__dirname, 'public')));
app.get('*', function(req, res){
    res.render('index', {
      console.log("called unnecessarily");
    });
});

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    console.log(req.url); 在我的钱在 favicon.ico 上的所有路线中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      相关资源
      最近更新 更多