我的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));当我向http://localhost:3000/api/posts发出get请求时,会收到以下info消息
info: Request won't be handled by connect-rest然后是一些关于找不到视图的错误,因为我还没有创建任何视图。如何让connect-rest处理这些请求?
发布于 2014-08-26 20:55:41
我也遇到了同样的问题,并通过将行app.use(rest.rester(apiOptions));移到定义第一个API方法(第一次使用rest.get(...))的行上来解决它。
https://stackoverflow.com/questions/24478627
复制相似问题