Merge pull request #176 from colkito/fix/cleanup-config-files-unnecessary
Fix/cleanup config files unnecessary
This commit is contained in:
commit
71ce49b9ef
|
@ -1,5 +1,5 @@
|
||||||
doctype html
|
doctype
|
||||||
html(lang='en', xmlns='http://www.w3.org/1999/xhtml', data-ng-app='insight')
|
html(lang='en', data-ng-app='insight')
|
||||||
include ../includes/head
|
include ../includes/head
|
||||||
body
|
body
|
||||||
#wrap
|
#wrap
|
||||||
|
|
|
@ -1,9 +1,41 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
var path = require('path'),
|
||||||
|
rootPath = path.normalize(__dirname + '/..'),
|
||||||
|
env;
|
||||||
|
|
||||||
// Load app configuration
|
switch(process.env.NODE_ENV) {
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
case 'production':
|
||||||
module.exports = _.extend(
|
env = 'prod';
|
||||||
require(__dirname + '/../config/env/all.js'),
|
break;
|
||||||
require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.js') || {});
|
case 'test':
|
||||||
|
env = 'test';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
env = 'dev';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root: rootPath,
|
||||||
|
appName: 'Insight ' + env,
|
||||||
|
port: process.env.PORT || 3000,
|
||||||
|
db: 'mongodb://localhost/insight-' + env,
|
||||||
|
bitcoind: {
|
||||||
|
protocol: process.env.BITCOIND_PROTO || 'http',
|
||||||
|
user: process.env.BITCOIND_USER || 'user',
|
||||||
|
pass: process.env.BITCOIND_PASS || 'pass',
|
||||||
|
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
||||||
|
port: process.env.BITCOIND_PORT || '18332',
|
||||||
|
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
||||||
|
|
||||||
|
// DO NOT CHANGE THIS!
|
||||||
|
disableAgent: true
|
||||||
|
},
|
||||||
|
network: process.env.INSIGHT_NETWORK || 'testnet',
|
||||||
|
disableP2pSync: false,
|
||||||
|
disableHistoricSync: false,
|
||||||
|
};
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var path = require('path'),
|
|
||||||
rootPath = path.normalize(__dirname + '/../..');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
root: rootPath,
|
|
||||||
port: process.env.PORT || 3000,
|
|
||||||
db: process.env.MONGOHQ_URL
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
db: 'mongodb://localhost/insight-dev',
|
|
||||||
app: {
|
|
||||||
name: 'Insight - Development'
|
|
||||||
},
|
|
||||||
bitcoind: {
|
|
||||||
protocol: process.env.BITCOIND_PROTO || 'http',
|
|
||||||
user: process.env.BITCOIND_USER || 'user',
|
|
||||||
pass: process.env.BITCOIND_PASS || 'pass',
|
|
||||||
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
|
||||||
port: process.env.BITCOIND_PORT || '18332',
|
|
||||||
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
|
||||||
disableAgent: true,
|
|
||||||
},
|
|
||||||
network: process.env.INSIGHT_NETWORK || 'testnet',
|
|
||||||
disableP2pSync: false,
|
|
||||||
disableHistoricSync: false,
|
|
||||||
};
|
|
|
@ -1,22 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
db: 'mongodb://localhost/insight-test',
|
|
||||||
app: {
|
|
||||||
name: 'Insight - Prod'
|
|
||||||
},
|
|
||||||
port: '3301',
|
|
||||||
bitcoind: {
|
|
||||||
protocol: process.env.BITCOIND_PROTO || 'http',
|
|
||||||
user: process.env.BITCOIND_USER || 'user',
|
|
||||||
pass: process.env.BITCOIND_PASS || 'pass',
|
|
||||||
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
|
||||||
port: process.env.BITCOIND_PORT || '18332',
|
|
||||||
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
|
||||||
disableAgent: true,
|
|
||||||
|
|
||||||
},
|
|
||||||
network: process.env.INSIGHT_NETWORK || 'testnet',
|
|
||||||
disableP2pSync: false,
|
|
||||||
disableHistoricSync: false,
|
|
||||||
};
|
|
|
@ -1,22 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
db: 'mongodb://localhost/insight-test',
|
|
||||||
app: {
|
|
||||||
name: 'Insight - Test'
|
|
||||||
},
|
|
||||||
port: '3301',
|
|
||||||
bitcoind: {
|
|
||||||
protocol: process.env.BITCOIND_PROTO || 'http',
|
|
||||||
user: process.env.BITCOIND_USER || 'user',
|
|
||||||
pass: process.env.BITCOIND_PASS || 'pass',
|
|
||||||
host: process.env.BITCOIND_HOST || '127.0.0.1',
|
|
||||||
port: process.env.BITCOIND_PORT || '18332',
|
|
||||||
p2pPort: process.env.BITCOIND_P2P_PORT || '18333',
|
|
||||||
disableAgent: true,
|
|
||||||
|
|
||||||
},
|
|
||||||
network: process.env.INSIGHT_NETWORK || 'testnet',
|
|
||||||
disableP2pSync: false,
|
|
||||||
disableHistoricSync: false,
|
|
||||||
};
|
|
|
@ -9,19 +9,14 @@ var express = require('express'),
|
||||||
|
|
||||||
module.exports = function(app, historicSync) {
|
module.exports = function(app, historicSync) {
|
||||||
|
|
||||||
|
//custom middleware
|
||||||
|
function setHistoric(req, res, next) {
|
||||||
|
req.historicSync = historicSync;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
app.set('showStackError', true);
|
app.set('showStackError', true);
|
||||||
|
|
||||||
//Prettify HTML
|
|
||||||
app.locals.pretty = true;
|
|
||||||
|
|
||||||
//Should be placed before express.static
|
|
||||||
app.use(express.compress({
|
|
||||||
filter: function(req, res) {
|
|
||||||
return (/json|text|javascript|css/).test(res.getHeader('Content-Type'));
|
|
||||||
},
|
|
||||||
level: 9
|
|
||||||
}));
|
|
||||||
|
|
||||||
//Set views path, template engine and default layout
|
//Set views path, template engine and default layout
|
||||||
app.set('views', config.root + '/app/views');
|
app.set('views', config.root + '/app/views');
|
||||||
app.set('view engine', 'jade');
|
app.set('view engine', 'jade');
|
||||||
|
@ -29,56 +24,41 @@ module.exports = function(app, historicSync) {
|
||||||
//Enable jsonp
|
//Enable jsonp
|
||||||
app.enable('jsonp callback');
|
app.enable('jsonp callback');
|
||||||
|
|
||||||
//custom middleware
|
|
||||||
function setHistoric(req, res, next) {
|
|
||||||
req.historicSync = historicSync;
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
app.use('/api/sync', setHistoric);
|
app.use('/api/sync', setHistoric);
|
||||||
|
app.use(express.logger('dev'));
|
||||||
app.configure(function() {
|
app.use(express.json());
|
||||||
|
app.use(express.urlencoded());
|
||||||
|
app.use(express.methodOverride());
|
||||||
|
app.use(express.compress());
|
||||||
|
|
||||||
//cookieParser should be above session
|
// IMPORTANT: for html5mode, this line must to be before app.router
|
||||||
app.use(express.cookieParser());
|
app.use(express.static(config.root + '/public'));
|
||||||
|
|
||||||
// request body parsing middleware should be above methodOverride
|
//dynamic helpers
|
||||||
app.use(express.urlencoded());
|
app.use(helpers(config.appName));
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.methodOverride());
|
|
||||||
|
|
||||||
//dynamic helpers
|
//routes should be at the last
|
||||||
app.use(helpers(config.app.name));
|
app.use(app.router);
|
||||||
|
|
||||||
// IMPORTAMT: for html5mode, this line must to be before app.router
|
//Assume "not found" in the error msgs is a 404. this is somewhat silly, but valid, you can do whatever you like, set properties, use instanceof etc.
|
||||||
app.use(express.static(config.root + '/public'));
|
app.use(function(err, req, res, next) {
|
||||||
|
//Treat as 404
|
||||||
|
if (~err.message.indexOf('not found')) return next();
|
||||||
|
|
||||||
//routes should be at the last
|
//Log it
|
||||||
app.use(app.router);
|
console.error(err.stack);
|
||||||
|
|
||||||
//Setting the fav icon and static folder
|
//Error page
|
||||||
app.use(express.favicon());
|
res.status(500).render('500', {
|
||||||
|
error: err.stack
|
||||||
//Assume "not found" in the error msgs is a 404. this is somewhat silly, but valid, you can do whatever you like, set properties, use instanceof etc.
|
|
||||||
app.use(function(err, req, res, next) {
|
|
||||||
//Treat as 404
|
|
||||||
if (~err.message.indexOf('not found')) return next();
|
|
||||||
|
|
||||||
//Log it
|
|
||||||
console.error(err.stack);
|
|
||||||
|
|
||||||
//Error page
|
|
||||||
res.status(500).render('500', {
|
|
||||||
error: err.stack
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Assume 404 since no middleware responded
|
//Assume 404 since no middleware responded
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res) {
|
||||||
res.status(404).render('404', {
|
res.status(404).render('404', {
|
||||||
url: req.originalUrl,
|
url: req.originalUrl,
|
||||||
error: 'Not found'
|
error: 'Not found'
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function(app, historicSync) {
|
module.exports = function(app) {
|
||||||
|
|
||||||
//Block routes
|
//Block routes
|
||||||
var blocks = require('../app/controllers/blocks');
|
var blocks = require('../app/controllers/blocks');
|
||||||
|
|
61
insight.js
61
insight.js
|
@ -1,10 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
//Load configurations
|
|
||||||
//Set the node enviornment variable if not set before
|
//Set the node enviornment variable if not set before
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
@ -15,48 +13,56 @@ var express = require('express'),
|
||||||
mongoose = require('mongoose');
|
mongoose = require('mongoose');
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main application entry file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//Initializing system variables
|
//Initializing system variables
|
||||||
var config = require('./config/config');
|
var config = require('./config/config');
|
||||||
|
|
||||||
//Bootstrap db connection
|
/**
|
||||||
|
* express app
|
||||||
|
*/
|
||||||
|
var expressApp = express();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap db connection
|
||||||
|
*/
|
||||||
// If mongod is running
|
// If mongod is running
|
||||||
mongoose.connection.on('open', function () {
|
mongoose.connection.on('open', function() {
|
||||||
console.log('Connected to mongo server.');
|
console.log('Connected to mongo server.');
|
||||||
});
|
});
|
||||||
|
|
||||||
// If mongod is not running
|
// If mongod is not running
|
||||||
mongoose.connection.on('error', function (err) {
|
mongoose.connection.on('error', function(err) {
|
||||||
console.log('Could not connect to mongo server!');
|
console.log('Could not connect to mongo server!');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
mongoose.connect(config.db);
|
mongoose.connect(config.db);
|
||||||
|
|
||||||
//Bootstrap models
|
/**
|
||||||
|
* Bootstrap models
|
||||||
|
*/
|
||||||
var models_path = __dirname + '/app/models';
|
var models_path = __dirname + '/app/models';
|
||||||
var walk = function(path) {
|
var walk = function(path) {
|
||||||
fs.readdirSync(path).forEach(function(file) {
|
fs.readdirSync(path).forEach(function(file) {
|
||||||
var newPath = path + '/' + file;
|
var newPath = path + '/' + file;
|
||||||
var stat = fs.statSync(newPath);
|
var stat = fs.statSync(newPath);
|
||||||
if (stat.isFile()) {
|
if (stat.isFile()) {
|
||||||
if (/(.*)\.(js$|coffee$)/.test(file)) {
|
if (/(.*)\.(js$)/.test(file)) {
|
||||||
require(newPath);
|
require(newPath);
|
||||||
}
|
}
|
||||||
} else if (stat.isDirectory()) {
|
}
|
||||||
|
else if (stat.isDirectory()) {
|
||||||
walk(newPath);
|
walk(newPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
walk(models_path);
|
walk(models_path);
|
||||||
|
|
||||||
// historic_sync process
|
/**
|
||||||
|
* historic_sync process
|
||||||
|
*/
|
||||||
var historicSync = {};
|
var historicSync = {};
|
||||||
|
|
||||||
|
|
||||||
if (!config.disableHistoricSync) {
|
if (!config.disableHistoricSync) {
|
||||||
historicSync = new HistoricSync();
|
historicSync = new HistoricSync();
|
||||||
|
|
||||||
|
@ -71,17 +77,17 @@ if (!config.disableHistoricSync) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
historicSync.smartImport(function(err){
|
historicSync.smartImport(function(err){
|
||||||
var txt= 'ended.';
|
var txt = 'ended.';
|
||||||
if (err) txt = 'ABORTED with error: ' + err.message;
|
if (err) txt = 'ABORTED with error: ' + err.message;
|
||||||
|
|
||||||
console.log('[historic_sync] ' + txt, historicSync.info());
|
console.log('[historic_sync] ' + txt, historicSync.info());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// p2p_sync process
|
* p2pSync process
|
||||||
|
*/
|
||||||
if (!config.disableP2pSync) {
|
if (!config.disableP2pSync) {
|
||||||
var ps = new PeerSync();
|
var ps = new PeerSync();
|
||||||
ps.init({
|
ps.init({
|
||||||
|
@ -94,26 +100,21 @@ if (!config.disableP2pSync) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// express app
|
|
||||||
/*global app: true*/
|
|
||||||
var app = express();
|
|
||||||
|
|
||||||
//express settings
|
//express settings
|
||||||
require('./config/express')(app, historicSync);
|
require('./config/express')(expressApp, historicSync);
|
||||||
|
|
||||||
//Bootstrap routes
|
//Bootstrap routes
|
||||||
require('./config/routes')(app);
|
require('./config/routes')(expressApp);
|
||||||
|
|
||||||
// socket.io
|
// socket.io
|
||||||
var server = require('http').createServer(app);
|
var server = require('http').createServer(expressApp);
|
||||||
var ios = require('socket.io').listen(server);
|
var ios = require('socket.io').listen(server);
|
||||||
require('./app/controllers/socket.js').init(app,ios);
|
require('./app/controllers/socket.js').init(expressApp, ios);
|
||||||
|
|
||||||
//Start the app by listening on <port>
|
//Start the app by listening on <port>
|
||||||
var port = process.env.PORT || config.port;
|
server.listen(config.port, function(){
|
||||||
server.listen(port, function(){
|
|
||||||
console.log('Express server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
console.log('Express server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
||||||
});
|
});
|
||||||
|
|
||||||
//expose app
|
//expose app
|
||||||
exports = module.exports = app;
|
exports = module.exports = expressApp;
|
||||||
|
|
Loading…
Reference in New Issue