我刚刚下载并开始玩 MEAN 堆栈(https://github.com/linnovate/mean),在我尝试和其他路由之前,一切正常。
//app/routes/hello.js:
'use strict';
module.exports = function(app, passport) {
app.get('/hello', function(req, res, next, id) {
console.log(req);
res.json(123456);
});
};
如果我将 app.routes 记录到,我可以看到路由:
{ path: '/hello',
method: 'get',
callbacks: [Object],
keys: [],
regexp: /^/hello/?$/i
}
我试过冰壶
curl http://localhost:3000/hello -Method GET
我得到404。
但是如果我得到/articles(这是 MEAN 中的示例路由之一。IO)
curl http://localhost:3000/articles -Method GET
它工作得很好。现在坐了几个小时,真的看不出路线的设置方式有任何区别。但是默认包含的路由有效,我尝试自己添加的所有路由都渲染 404。
所以总结一下,干净的意思。IO 分叉。默认路由工作,我添加的路由,结果为 404。
将路由配置更改为:
'use strict';
module.exports = function(app, passport) {
app.get('/hello', function(req, res) {
console.log(req);
res.json(123456);
});
};
让它工作,真的不知道为什么。
为什么在应用程序内的回调函数中有第四个参数(id)。
**要求 -请求
回复
Next 将控件传递给下一个函数。
试试这个:
'use strict';
module.exports = function(app, passport) {
app.get('/hello', function(req, res, next) {
console.log(req);
res.json(123456);
});
};