我有 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");
});
});
最佳答案
在 catch all 路由中执行 console.log(req.url);
我的钱在 favicon.ico 上。
关于node.js - 快速 3 条路线被不必要地调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18153117/