Node.js 连接Rest而不处理请求

Node.js 连接Rest而不处理请求,node.js,rest,express,connect,Node.js,Rest,Express,Connect,我在app.js文件中有这个代码来处理api请求 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

我在app.js文件中有这个代码来处理api请求

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));
当我向
get请求时http://localhost:3000/api/posts
我收到了这条信息消息

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

之后是一些关于找不到视图的错误,因为我还没有创建任何视图。如何让connect rest处理这些请求?

我遇到了同样的问题,通过移动行
app.use(rest.rester(apipoptions)),解决了这个问题位于定义第一个API方法的行上方(第一次使用
rest.get(…)