首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Connect-Rest不处理请求

Connect-Rest不处理请求
EN

Stack Overflow用户
提问于 2014-06-30 01:43:16
回答 1查看 509关注 0票数 1

我的app.js文件中有这段代码来处理api请求。

代码语言:javascript
复制
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));

当我向http://localhost:3000/api/posts发出get请求时,会收到以下info消息

代码语言:javascript
复制
info: Request won't be handled by connect-rest

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

EN

回答 1

Stack Overflow用户

发布于 2014-08-26 20:55:41

我也遇到了同样的问题,并通过将行app.use(rest.rester(apiOptions));移到定义第一个API方法(第一次使用rest.get(...))的行上来解决它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24478627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档