1
我正在研究MEAN堆栈这一天,所以我做了一些示例应用程序遵循指导。我几小时前制作了“Bookshelf”应用程序,这是由谷歌云服务提供的,所以我应该深入研究示例代码以了解其工作原理。平均堆栈:想知道api.js和crud.js
所有源码:https://github.com/GoogleCloudPlatform/nodejs-getting-started/tree/master/2-structured-data
示例应用:http://mymongo-1165.appspot.com/books
书籍/ api.js
router.get('/', function list(req, res) {
model.list(10, req.query.pageToken,
function(err, entities, cursor) {
if (err) { return handleRpcError(err, res); }
res.json({
items: entities,
nextPageToken: cursor
});
});
});
书籍/ curd.js
router.get('/', function list(req, res) {
model.list(10, req.query.pageToken,
function(err, entities, cursor) {
if (err) { return handleRpcError(err, res); }
res.render('books/list.jade', {
books: entities,
nextPageToken: cursor
});
}
);
});
这两个代码是相似的,但我不知道为什么这些类似的代码出现。我认为crud.js够了,但为什么api.js出现了。你能否解释这两个代码是如何工作的?
api返回结果为JSON,curd返回一个渲染页面。 – Gary