Folder structure #398

Merged
bones7242 merged 76 commits from folder-structure into master 2018-03-20 00:01:08 +01:00
14 changed files with 58549 additions and 101 deletions
Showing only changes of commit bdd2d45ab5 - Show all commits

View file

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

View file

@ -1,3 +1,5 @@
module.exports = { const loggerConfig = {
logLevel: 'debug', // options: silly, debug, verbose, info logLevel: 'debug', // options: silly, debug, verbose, info
}; };
module.exports = loggerConfig;

12
config/mysqlConfig.js Normal file
View file

@ -0,0 +1,12 @@
function MysqlConfig () {
this.database = 'default';
this.username = 'default';
this.password = 'default';
this.configure = ({database, username, password}) => {
if (database) this.database = database;
if (username) this.username = username;
if (password) this.password = password;
};
};
module.exports = new MysqlConfig();

View file

@ -1,4 +1,4 @@
module.exports = { const sequelizeCliConfig = {
development: { development: {
username: 'lbry', username: 'lbry',
password: 'yYa5B6f7WuGq1613q9D7UWP3HT', password: 'yYa5B6f7WuGq1613q9D7UWP3HT',
@ -21,3 +21,5 @@ module.exports = {
dialect : 'mysql', dialect : 'mysql',
}, },
}; };
module.exports = sequelizeCliConfig;

12
config/slackConfig.js Normal file
View file

@ -0,0 +1,12 @@
function SlackConfig () {
this.slackWebHook = 'default';
this.slackErrorChannel = 'default';
this.slackInfoChannel = 'default';
this.configure = ({slackWebHook, slackErrorChannel, slackInfoChannel}) => {
if (slackWebHook) this.slackWebHook = slackWebHook;
if (slackErrorChannel) this.slackErrorChannel = slackErrorChannel;
if (slackInfoChannel) this.slackInfoChannel = slackInfoChannel;
};
};
module.exports = new SlackConfig();

View file

@ -1,4 +1,4 @@
module.exports = { const speechConfig = {
analytics: { analytics: {
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
}, },
@ -26,3 +26,5 @@ module.exports = {
defaultDescription: 'Open-source, decentralized image and video sharing.', defaultDescription: 'Open-source, decentralized image and video sharing.',
}, },
}; };
module.exports = speechConfig;

View file

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

View file

@ -1,6 +1,7 @@
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook; const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
const slackConfig = require('../config/slackConfig.js');
module.exports = (winston, slackConfig) => { module.exports = (winston) => {
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig; const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
if (slackWebHook) { if (slackWebHook) {
// add a transport for errors to slack // add a transport for errors to slack

10773
index.js

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,8 +1,8 @@
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const logger = require('winston'); const logger = require('winston');
module.exports = (mysqlConfig) => { console.log('exporting sequelize models');
const { database, username, password } = mysqlConfig; const { database, username, password } = require('../config/mysqlConfig');
const db = {}; const db = {};
// set sequelize options // set sequelize options
const sequelize = new Sequelize(database, username, password, { const sequelize = new Sequelize(database, username, password, {
@ -74,5 +74,4 @@ module.exports = (mysqlConfig) => {
}); });
}; };
return db; module.exports = db;
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -7,28 +7,35 @@ const helmet = require('helmet');
const passport = require('passport'); const passport = require('passport');
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js'); const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const cookieSession = require('cookie-session'); const cookieSession = require('cookie-session');
const http = require('http');
// logging dependencies // logging dependencies
const logger = require('winston'); const logger = require('winston');
function SpeechServer ({mysqlConfig, siteConfig, slackConfig, lbrynetConfig}) { function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
this.mysqlConfig = mysqlConfig;
this.siteConfig = siteConfig;
this.slackConfig = slackConfig;
this.lbrynetConfig = lbrynetConfig;
this.db = require('./models')(mysqlConfig);
this.PORT = 3000; this.PORT = 3000;
this.speak = (something) => { this.speak = (something) => {
console.log(something); console.log(something);
}; };
this.start = () => { this.start = () => {
this.configureConfigFiles();
this.configureLogging(); this.configureLogging();
this.configureApp(); this.configureApp();
this.configureServer(); this.configureServer();
this.startServer(); this.startServer();
}; };
this.configureConfigFiles = () => {
const mysqlAppConfig = require('./config/mysqlConfig.js');
mysqlAppConfig.configure(mysqlConfig);
const slackAppConfig = require('./config/slackConfig.js');
slackAppConfig.configure(slackConfig);
// print the config variables
console.log('configured config files');
require('./helpers/configVarCheck.js')(mysqlAppConfig);
require('./helpers/configVarCheck.js')(slackAppConfig);
};
this.configureLogging = () => { this.configureLogging = () => {
require('./helpers/configureLogger.js')(logger); require('./helpers/configureLogger.js')(logger);
require('./helpers/configureSlack.js')(logger, this.slackConfig); require('./helpers/configureSlack.js')(logger);
}; };
this.configureApp = () => { this.configureApp = () => {
const app = express(); // create an Express application const app = express(); // create an Express application
@ -49,14 +56,14 @@ function SpeechServer ({mysqlConfig, siteConfig, slackConfig, lbrynetConfig}) {
// configure passport // configure passport
passport.serializeUser(serializeSpeechUser); passport.serializeUser(serializeSpeechUser);
passport.deserializeUser(deserializeSpeechUser); passport.deserializeUser(deserializeSpeechUser);
const localSignupStrategy = require('./passport/local-signup.js')(this.db); const localSignupStrategy = require('./passport/local-signup.js');
const localLoginStrategy = require('./passport/local-login.js')(this.db); const localLoginStrategy = require('./passport/local-login.js');
passport.use('local-signup', localSignupStrategy); passport.use('local-signup', localSignupStrategy);
passport.use('local-login', localLoginStrategy); passport.use('local-login', localLoginStrategy);
// initialize passport // initialize passport
app.use(cookieSession({ app.use(cookieSession({
name : 'session', name : 'session',
keys : [this.siteConfig.session.sessionKey], keys : [siteConfig.session.sessionKey],
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
})); }));
app.use(passport.initialize()); app.use(passport.initialize());
@ -83,15 +90,12 @@ function SpeechServer ({mysqlConfig, siteConfig, slackConfig, lbrynetConfig}) {
this.app = app; this.app = app;
}; };
this.configureServer = () => { this.configureServer = () => {
const http = require('http');
this.server = http.Server(this.app); this.server = http.Server(this.app);
}; };
this.startServer = () => { this.startServer = () => {
// print config variables const db = require('./models');
require('./helpers/configVarCheck.js')(this.config);
this.db.sequelize
// sync sequelize // sync sequelize
.sync() db.sequelize.sync()
// start the server // start the server
.then(() => { .then(() => {
this.server.listen(this.PORT, () => { this.server.listen(this.PORT, () => {