문제

I just downloaded and started playing with the MEAN stack(https://github.com/linnovate/mean), everything works fine until i try and additional routes.

//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);
    });
};

If i log app.routes to I can see the route:

{ path: '/hello',
  method: 'get',
  callbacks: [Object],
  keys: [],
  regexp: /^\/hello\/?$/i 
}

I have tried curling to

curl http://localhost:3000/hello -Method GET

I get 404.

But if i get /articles (which is one of the sample routes in MEAN.IO)

curl http://localhost:3000/articles -Method GET

It works just fine. Sitting a couple of hours now and really cant see any difference in how the routes are setup. But the ones included by default works, all routes i try to add myself renders 404.

So to conclude, clean MEAN.IO fork. Default routes work, routes i add, results in 404.

도움이 되었습니까?

해결책

Changing the route config to:

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

Made it work, don't really know why.

다른 팁

why there is a fourth parameter(id) in the callback function inside app.

**req -Request

res-Response

next-to pass the control to next function.**

Try this:

'use strict';
 module.exports = function(app, passport) {
 app.get('/hello', function(req, res, next) {
    console.log(req);
    res.json(123456);
  });
 };
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top