Connect-Rest not handling requests

I have this code in my app.js file to handle api requests

app.use('/api', cors());
rest.get('/posts', function(req, content, cb) {
  Post.find(function(err, posts) {
    if (err) return cb({error: 'Internal error.'});
    cb(null, posts.map(function(p) {
      return {
        title: p.title
      };
    }));
  });
});

var apiOptions = {
  context: '/api',
  domain: require('domain').create(),
};

apiOptions.domain.on('error', function(err){
  console.log('API domain error.\n', err.stack);
  setTimeout(function(){
    console.log('Server shutting down after API domain error.');
    process.exit(1);
  }, 5000);
  server.close();
});

app.use(rest.rester(apiOptions));

When I make a get request to http://localhost:3000/api/posts I get this info message

info: Request won't be handled by connect-rest

And then after is some errors about not finding views because I haven't made any views yet. How can I get connect-rest to handle these requests?

Answers


I had the same problem and solved it by moving the line app.use(rest.rester(apiOptions)); above the line where the first API method is defined (first usage ofrest.get(...)).


Need Your Help

NSPredicateEditorRowTemplate views not filled with predicate

cocoa nspredicateeditor

I have an NSPredicateEditor for which I'm setting up custom template row views.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.