For blocks info, we always use controller blocks. Index controller only render homepage

This commit is contained in:
Gustavo Cortez 2014-01-08 09:17:41 -03:00
parent 76862dc0f9
commit c2bbdb2941
3 changed files with 16 additions and 23 deletions

View File

@ -29,3 +29,18 @@ exports.show = function(req, res) {
res.jsonp(req.block);
};
/**
* List of blocks at HomePage
*/
exports.last_blocks = function(req, res) {
Block.find().limit(7).exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};

View File

@ -1,27 +1,5 @@
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block');
exports.render = function(req, res) {
res.render('index');
};
/**
* List of blocks at HomePage
*/
exports.all = function(req, res) {
Block.find().limit(7).exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};

View File

@ -5,12 +5,12 @@ module.exports = function(app) {
//Home route
var index = require('../app/controllers/index');
app.get('/', index.render);
app.get('/last_blocks', index.all);
//Block routes
var blocks = require('../app/controllers/blocks');
app.get('/block/:blockHash', blocks.show);
app.param('blockHash', blocks.block);
app.get('/last_blocks', blocks.last_blocks);
var transactions = require('../app/controllers/transactions');
app.get('/tx/:txid', transactions.show);