MEAN堆栈路由问题

时间:2014-03-29 19:10:10

标签: node.js express mean-stack

我刚刚下载并开始使用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。

总而言之,清理MEAN.IO fork。默认路由工作,我添加的路由,结果为404。

2 个答案:

答案 0 :(得分:1)

将路线配置更改为:

'use strict';
module.exports = function(app, passport) {
    app.get('/hello', function(req, res) {
        console.log(req);
        res.json(123456);
    });
};

让它工作,不知道为什么。

答案 1 :(得分:0)

为什么应用内的回调函数中有一个第四个参数(id)

** req -Request

res-Response

下一步-将控件传递给下一个功能。**

尝试一下:

'use strict';
 module.exports = function(app, passport) {
 app.get('/hello', function(req, res, next) {
    console.log(req);
    res.json(123456);
  });
 };