【发布时间】:2014-08-26 20:55:41
【问题描述】:
我的 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 发出获取请求时,我会收到此信息消息
info: Request won't be handled by connect-rest
然后是一些关于找不到视图的错误,因为我还没有发表任何视图。如何让 connect-rest 处理这些请求?
【问题讨论】:
标签: node.js rest express connect