reorganized server startup functions

This commit is contained in:
bill bittner 2018-03-09 10:56:22 -08:00
parent 34603fbcd6
commit 662e468df6
12 changed files with 51 additions and 34 deletions

6
config/lbryConfig.js Normal file
View file

@ -0,0 +1,6 @@
module.exports = {
api: {
apiHost: 'localhost',
apiPort: '5279',
},
};

View file

@ -1,4 +1,7 @@
module.exports = (winston, logLevel) => { const logLevel = 'debug'; // options: silly, debug, verbose, info
module.exports = (winston) => {
// configure
winston.configure({ winston.configure({
transports: [ transports: [
new (winston.transports.Console)({ new (winston.transports.Console)({
@ -11,7 +14,7 @@ module.exports = (winston, logLevel) => {
}), }),
], ],
}); });
// test all the log levels
winston.error('Level 0'); winston.error('Level 0');
winston.warn('Level 1'); winston.warn('Level 1');
winston.info('Level 2'); winston.info('Level 2');

View file

@ -3,7 +3,6 @@ module.exports = {
googleId: 'UA-60403362-6', // google id for analytics tracking; leave `null` if not applicable googleId: 'UA-60403362-6', // google id for analytics tracking; leave `null` if not applicable
}, },
logging: { logging: {
logLevel : 'debug', // options: silly, debug, verbose, info
slackWebHook : 'https://hooks.slack.com/services/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', // enter a webhook if you wish to push logs to slack; otherwise leave as `null` slackWebHook : 'https://hooks.slack.com/services/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', // enter a webhook if you wish to push logs to slack; otherwise leave as `null`
slackErrorChannel: null, // enter a slack channel (#example) for errors to be sent to; otherwise leave null slackErrorChannel: null, // enter a slack channel (#example) for errors to be sent to; otherwise leave null
slackInfoChannel : '#speech-dev1-errors', // enter a slack channel (#info) for info level logs to be sent to otherwise leave null slackInfoChannel : '#speech-dev1-errors', // enter a slack channel (#info) for info level logs to be sent to otherwise leave null
@ -31,13 +30,4 @@ module.exports = {
defaultThumbnail : 'https://spee.ch/assets/img/video_thumb_default.png', defaultThumbnail : 'https://spee.ch/assets/img/video_thumb_default.png',
defaultDescription: 'Open-source, decentralized image and video sharing.', defaultDescription: 'Open-source, decentralized image and video sharing.',
}, },
testing: {
testChannel : '@test', // a channel to make test publishes in
testChannelId : '3b5bc6b6819172c6e2f3f90aa855b14a956b4a82', // the claim id for the test channel
testChannelPassword: '1234', // password for the test channel
},
api: {
apiHost: 'localhost',
apiPort: '5279',
},
}; };

View file

@ -0,0 +1,5 @@
module.exports = {
testChannel : null, // a channel to make test publishes in
testChannelId : null, // the claim id for the test channel
testChannelPassword: null, // password for the test channel
};

5
config/testingConfig.js Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
testChannel : '@test',
testChannelId : '3b5bc6b6819172c6e2f3f90aa855b14a956b4a82',
testChannelPassword: '1234',
};

View file

@ -1,6 +1,6 @@
const axios = require('axios'); const axios = require('axios');
const logger = require('winston'); const logger = require('winston');
const { api: { apiHost, apiPort } } = require('../config/speechConfig.js'); const { api: { apiHost, apiPort } } = require('../config/lbryConfig.js');
const lbryApiUri = 'http://' + apiHost + ':' + apiPort; const lbryApiUri = 'http://' + apiHost + ':' + apiPort;
const { chooseGaLbrynetPublishLabel, sendGATimingEvent } = require('./googleAnalytics.js'); const { chooseGaLbrynetPublishLabel, sendGATimingEvent } = require('./googleAnalytics.js');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,19 +1,14 @@
// load dependencies // app dependencies
const express = require('express'); const express = require('express');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const expressHandlebars = require('express-handlebars'); const expressHandlebars = require('express-handlebars');
const Handlebars = require('handlebars'); const Handlebars = require('handlebars');
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const { logging: { logLevel } } = require('./config/speechConfig.js');
const logger = require('winston');
const helmet = require('helmet'); const helmet = require('helmet');
const app = express(); // create an Express application
const passport = require('passport'); const passport = require('passport');
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const cookieSession = require('cookie-session'); const cookieSession = require('cookie-session');
// logging dependencies
// configure logging const logger = require('winston');
require('./config/loggerConfig.js')(logger, logLevel);
require('./config/slackConfig.js')(logger);
function SpeechServer (config) { function SpeechServer (config) {
this.mysqlConfig = config.mysql; this.mysqlConfig = config.mysql;
@ -25,6 +20,18 @@ function SpeechServer (config) {
console.log(something); console.log(something);
}; };
this.start = () => { this.start = () => {
this.configureLogging();
this.configureApp();
this.configureServer();
this.startServer();
};
this.configureLogging = () => {
require('./config/loggerConfig.js')(logger);
require('./config/slackConfig.js')(logger);
};
this.configureApp = () => {
const app = express(); // create an Express application
// trust the proxy to get ip address for us // trust the proxy to get ip address for us
app.enable('trust proxy'); app.enable('trust proxy');
@ -72,11 +79,13 @@ function SpeechServer (config) {
require('./routes/serve-routes.js')(app); require('./routes/serve-routes.js')(app);
require('./routes/fallback-routes.js')(app); require('./routes/fallback-routes.js')(app);
const http = require('http'); this.app = app;
const server = http.Server(app);
this.startServer(server);
}; };
this.startServer = (server) => { this.configureServer = () => {
const http = require('http');
this.server = http.Server(this.app);
};
this.startServer = () => {
// print config variables // print config variables
require('./helpers/configVarCheck.js')(this.config); require('./helpers/configVarCheck.js')(this.config);
this.db.sequelize this.db.sequelize
@ -84,7 +93,7 @@ function SpeechServer (config) {
.sync() .sync()
// start the server // start the server
.then(() => { .then(() => {
server.listen(this.PORT, () => { this.server.listen(this.PORT, () => {
logger.info(`Server is listening on PORT ${this.PORT}`); logger.info(`Server is listening on PORT ${this.PORT}`);
}); });
}) })

View file

@ -1,9 +1,8 @@
const chai = require('chai'); const chai = require('chai');
const expect = chai.expect; const expect = chai.expect;
const chaiHttp = require('chai-http'); const chaiHttp = require('chai-http');
const { site, testing } = require('../../config/speechConfig.js'); const { site: { host } } = require('../../config/speechConfig.js');
const { host } = site; const { testChannel, testChannelId, testChannelPassword } = require('../../config/testingConfig.js');
const { testChannel, testChannelId, testChannelPassword } = testing;
const requestTimeout = 20000; const requestTimeout = 20000;
const publishTimeout = 120000; const publishTimeout = 120000;
const fs = require('fs'); const fs = require('fs');