commit
7d69c1fb90
4 changed files with 57 additions and 10 deletions
|
@ -25,12 +25,11 @@ function LoggerConfig () {
|
|||
});
|
||||
// test all the log levels
|
||||
logger.info('testing winston log levels...');
|
||||
logger.error('Level 0');
|
||||
logger.warn('Level 1');
|
||||
logger.info('Level 2');
|
||||
logger.verbose('Level 3');
|
||||
logger.debug('Level 4');
|
||||
logger.silly('Level 5');
|
||||
logger.warn('Testing: Log Level 1');
|
||||
logger.info('Testing: Log Level 2');
|
||||
logger.verbose('Testing: Log Level 3');
|
||||
logger.debug('Testing: Log Level 4');
|
||||
logger.silly('Testing: Log Level 5');
|
||||
};
|
||||
};
|
||||
|
||||
|
|
19
index.js
19
index.js
|
@ -13,6 +13,8 @@ const loggerConfig = require('./config/loggerConfig.js');
|
|||
const mysqlConfig = require('./config/mysqlConfig.js');
|
||||
const siteConfig = require('./config/siteConfig.js');
|
||||
const slackConfig = require('./config/slackConfig.js');
|
||||
const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js');
|
||||
const { getWalletBalance } = require('./server/lbrynet');
|
||||
|
||||
function Server () {
|
||||
this.configureLogger = loggerConfig.update;
|
||||
|
@ -81,15 +83,24 @@ function Server () {
|
|||
const db = require('./server/models');
|
||||
const PORT = siteConfig.details.port;
|
||||
// sync sequelize
|
||||
db.sequelize.sync()
|
||||
// start the server
|
||||
createDatabaseIfNotExists()
|
||||
.then(() => {
|
||||
return getWalletBalance();
|
||||
})
|
||||
.then(balance => {
|
||||
logger.info('starting LBC balance:', balance);
|
||||
db.sequelize.sync();
|
||||
this.server.listen(PORT, () => {
|
||||
logger.info(`Server is listening on PORT ${PORT}`);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(`Startup Error:`, error);
|
||||
.catch(error => {
|
||||
if (error.code === 'ECONNREFUSED') {
|
||||
return logger.error('Connection refused. The daemon may not be running.')
|
||||
} else if (error.message) {
|
||||
logger.error(error.message);
|
||||
}
|
||||
logger.error(error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -125,4 +125,20 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
},
|
||||
getWalletBalance () {
|
||||
const gaStartTime = Date.now();
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(lbrynetUri, {
|
||||
method: 'wallet_balance',
|
||||
})
|
||||
.then(response => {
|
||||
sendGATimingEvent('lbrynet', 'getWalletBalance', 'SETTINGS_GET', gaStartTime, Date.now());
|
||||
handleLbrynetResponse(response, resolve, reject);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
21
server/models/utils/createDatabaseIfNotExists.js
Normal file
21
server/models/utils/createDatabaseIfNotExists.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
const createDatabaseIfNotExists = () => {
|
||||
const {database, username, password} = require('../../../config/mysqlConfig.js');
|
||||
const sequelize = new Sequelize('', username, password, {
|
||||
dialect : 'mysql',
|
||||
logging : false,
|
||||
operatorsAliases: false,
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`)
|
||||
.then(() => {
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = createDatabaseIfNotExists;
|
Loading…
Reference in a new issue