1
我有這樣的代碼在我的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
之後是關於找不到視圖的一些錯誤,因爲我還沒有發表任何意見。我如何獲得連接休息來處理這些請求?