moved passport info into package
This commit is contained in:
parent
955a2f5e14
commit
195f193259
17 changed files with 376 additions and 311 deletions
|
@ -1,16 +1,95 @@
|
|||
const Sequelize = require('sequelize');
|
||||
const logger = require('winston');
|
||||
|
||||
function mysql () {
|
||||
this.database = 'default';
|
||||
this.username = 'default';
|
||||
this.password = 'default';
|
||||
this.db = {};
|
||||
this.configure = (config) => {
|
||||
if (!config) {
|
||||
return console.log('No MySQL config received.');
|
||||
}
|
||||
// configure credentials
|
||||
console.log('configuring mysql credentials...');
|
||||
const {database, username, password} = config;
|
||||
this.database = database;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
// configure db
|
||||
// set sequelize options
|
||||
const sequelize = new Sequelize(database, username, password, {
|
||||
host : 'localhost',
|
||||
dialect : 'mysql',
|
||||
dialectOptions: {decimalNumbers: true},
|
||||
logging : false,
|
||||
pool : {
|
||||
max : 5,
|
||||
min : 0,
|
||||
idle : 10000,
|
||||
acquire: 10000,
|
||||
},
|
||||
});
|
||||
|
||||
// establish mysql connection
|
||||
sequelize
|
||||
.authenticate()
|
||||
.then(() => {
|
||||
logger.info('Sequelize has established mysql connection successfully.');
|
||||
})
|
||||
.catch(err => {
|
||||
logger.debug('mysqlconfig', { database, username, password });
|
||||
logger.error('Sequelize was unable to connect to the database:', err);
|
||||
});
|
||||
|
||||
// manually add each model to the db object (note: make this dynamic)
|
||||
const db = {};
|
||||
const Certificate = require('models/certificate.js');
|
||||
const Channel = require('models/channel.js');
|
||||
const Claim = require('models/claim.js');
|
||||
const File = require('models/file.js');
|
||||
const Request = require('models/request.js');
|
||||
const User = require('models/user.js');
|
||||
db['Certificate'] = sequelize.import('Certificate', Certificate);
|
||||
db['Channel'] = sequelize.import('Channel', Channel);
|
||||
db['Claim'] = sequelize.import('Claim', Claim);
|
||||
db['File'] = sequelize.import('File', File);
|
||||
db['Request'] = sequelize.import('Request', Request);
|
||||
db['User'] = sequelize.import('User', User);
|
||||
|
||||
// run model.association for each model in the db object that has an association
|
||||
logger.info('associating db models...');
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
logger.info('Associating model:', modelName);
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
// add sequelize/Sequelize to db
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
// add an 'upsert' method to the db object
|
||||
db.upsert = (Model, values, condition, tableName) => {
|
||||
return Model
|
||||
.findOne({
|
||||
where: condition,
|
||||
})
|
||||
.then(obj => {
|
||||
if (obj) { // update
|
||||
logger.debug(`updating record in db.${tableName}`);
|
||||
return obj.update(values);
|
||||
} else { // insert
|
||||
logger.debug(`creating record in db.${tableName}`);
|
||||
return Model.create(values);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
logger.error(`${tableName}.upsert error`, error);
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
this.db = db;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
340
index.js
340
index.js
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
const db = require('../models');
|
||||
const { db } = require('mysqlConfig');
|
||||
const logger = require('winston');
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../models');
|
||||
const { db } = require('mysqlConfig');
|
||||
const lbryApi = require('../helpers/lbryApi.js');
|
||||
const publishHelpers = require('../helpers/publishHelpers.js');
|
||||
const { publishing: { primaryClaimAddress, additionalClaimAddresses } } = require('../../config/siteConfig.js');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const db = require('../models/index');
|
||||
const { db } = require('mysqlConfig');
|
||||
const logger = require('winston');
|
||||
const { returnPaginatedChannelClaims } = require('../helpers/channelPagination.js');
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../models/index');
|
||||
const { db } = require('mysqlConfig');
|
||||
|
||||
module.exports = {
|
||||
getRecentClaims () {
|
||||
|
|
10
server/helpers/authHelpers.js
Normal file
10
server/helpers/authHelpers.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
serializeSpeechUser (user, done) { // returns user data to be serialized into session
|
||||
console.log('serializing user');
|
||||
done(null, user);
|
||||
},
|
||||
deserializeSpeechUser (user, done) { // deserializes session and populates additional info to req.user
|
||||
console.log('deserializing user');
|
||||
done(null, user);
|
||||
},
|
||||
};
|
|
@ -1,6 +1,5 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../models/index');
|
||||
|
||||
const { db } = require('mysqlConfig');
|
||||
module.exports = {
|
||||
postToStats (action, url, ipAddress, name, claimId, result) {
|
||||
logger.debug('action:', action);
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
const Sequelize = require('sequelize');
|
||||
const logger = require('winston');
|
||||
|
||||
logger.info('exporting sequelize models');
|
||||
const mysqlConfig = require('../../config/mysqlConfig');
|
||||
const { database, username, password } = mysqlConfig;
|
||||
|
||||
const db = {};
|
||||
// set sequelize options
|
||||
const sequelize = new Sequelize(database, username, password, {
|
||||
host : 'localhost',
|
||||
dialect : 'mysql',
|
||||
dialectOptions: {decimalNumbers: true}, // fix to ensure DECIMAL will not be stored as a string
|
||||
logging : false,
|
||||
pool : {
|
||||
max : 5,
|
||||
min : 0,
|
||||
idle : 10000,
|
||||
acquire: 10000,
|
||||
},
|
||||
});
|
||||
|
||||
// establish mysql connection
|
||||
sequelize
|
||||
.authenticate()
|
||||
.then(() => {
|
||||
logger.info('Sequelize has established mysql connection successfully.');
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Sequelize was unable to connect to the database:', err);
|
||||
});
|
||||
|
||||
// manually add each model to the db object
|
||||
const Certificate = require('./certificate.js');
|
||||
const Channel = require('./channel.js');
|
||||
const Claim = require('./claim.js');
|
||||
const File = require('./file.js');
|
||||
const Request = require('./request.js');
|
||||
const User = require('./user.js');
|
||||
db['Certificate'] = sequelize.import('Certificate', Certificate);
|
||||
db['Channel'] = sequelize.import('Channel', Channel);
|
||||
db['Claim'] = sequelize.import('Claim', Claim);
|
||||
db['File'] = sequelize.import('File', File);
|
||||
db['Request'] = sequelize.import('Request', Request);
|
||||
db['User'] = sequelize.import('User', User);
|
||||
|
||||
// run model.association for each model in the db object that has an association
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
logger.info('Associating model:', modelName);
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
// add an 'upsert' method to the db object
|
||||
db.upsert = (Model, values, condition, tableName) => {
|
||||
return Model
|
||||
.findOne({
|
||||
where: condition,
|
||||
})
|
||||
.then(obj => {
|
||||
if (obj) { // update
|
||||
logger.debug(`updating record in db.${tableName}`);
|
||||
return obj.update(values);
|
||||
} else { // insert
|
||||
logger.debug(`creating record in db.${tableName}`);
|
||||
return Model.create(values);
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
logger.error(`${tableName}.upsert error`, error);
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = db;
|
11
server/passport/index.js
Normal file
11
server/passport/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const passport = require('passport');
|
||||
const localLoginStrategy = require('./local-login.js');
|
||||
const localSignupStrategy = require('./local-signup.js');
|
||||
const { serializeSpeechUser, deserializeSpeechUser } = require('../helpers/authHelpers.js');
|
||||
|
||||
passport.deserializeUser(deserializeSpeechUser);
|
||||
passport.serializeUser(serializeSpeechUser);
|
||||
passport.use('local-login', localLoginStrategy);
|
||||
passport.use('local-signup', localSignupStrategy);
|
||||
|
||||
module.exports = passport;
|
|
@ -1,6 +1,6 @@
|
|||
const PassportLocalStrategy = require('passport-local').Strategy;
|
||||
const logger = require('winston');
|
||||
const db = require('../models');
|
||||
const { db } = require('mysqlConfig');
|
||||
|
||||
const returnUserAndChannelInfo = (userInstance) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const PassportLocalStrategy = require('passport-local').Strategy;
|
||||
const lbryApi = require('../helpers/lbryApi.js');
|
||||
const logger = require('winston');
|
||||
const db = require('../models');
|
||||
const { db } = require('mysqlConfig');
|
||||
|
||||
module.exports = new PassportLocalStrategy(
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const logger = require('winston');
|
||||
const { details: { host } } = require('../../config/siteConfig.js');
|
||||
const db = require('../models');
|
||||
const { db } = require('../../config/mysqlConfig.js');
|
||||
const { claimNameIsAvailable, checkChannelAvailability, publish } = require('../controllers/publishController.js');
|
||||
const { getClaimList, resolveUri, getClaim } = require('../helpers/lbryApi.js');
|
||||
const { addGetResultsToFileData, createBasicPublishParams, createThumbnailPublishParams, parsePublishApiRequestBody, parsePublishApiRequestFiles, createFileData } = require('../helpers/publishHelpers.js');
|
||||
|
@ -12,7 +12,7 @@ const { getChannelData, getChannelClaims, getClaimId } = require('../controllers
|
|||
const NO_CHANNEL = 'NO_CHANNEL';
|
||||
const NO_CLAIM = 'NO_CLAIM';
|
||||
|
||||
module.exports = {
|
||||
const apiRoutes = {
|
||||
// route to check whether site has published to a channel
|
||||
channelAvailabilityRoute ({ ip, originalUrl, params: { name } }, res) {
|
||||
const gaStartTime = Date.now();
|
||||
|
@ -27,6 +27,9 @@ module.exports = {
|
|||
},
|
||||
// route to get a short channel id from long channel Id
|
||||
channelShortIdRoute ({ ip, originalUrl, params }, res) {
|
||||
console.log('hello');
|
||||
logger.debug('host:', host);
|
||||
logger.debug('db:', db);
|
||||
db.Certificate.getShortChannelIdFromLongChannelId(params.longId, params.name)
|
||||
.then(shortId => {
|
||||
res.status(200).json(shortId);
|
||||
|
@ -238,3 +241,5 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = apiRoutes;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// load dependencies
|
||||
const logger = require('winston');
|
||||
const db = require('../models'); // require our models for syncing
|
||||
const { db } = require('mysqlConfig');
|
||||
// configure logging
|
||||
require('../helpers/configureLogger.js')(logger);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// load dependencies
|
||||
const logger = require('winston');
|
||||
const db = require('../models/index');
|
||||
const { db } = require('mysqlConfig');
|
||||
// configure logging
|
||||
require('../helpers/configureLogger.js')(logger);
|
||||
|
||||
|
|
18
speech.js
18
speech.js
|
@ -1,31 +1,23 @@
|
|||
// const Server = require('./server/server.js');
|
||||
// const Components = require('./client/components');
|
||||
// const Containers = require('./client/containers');
|
||||
// const Pages = require('./client/pages');
|
||||
const apiRoutes = require('./server/routes/apiRoutes.js');
|
||||
const logger = require('./config/loggerConfig.js');
|
||||
const mysql = require('./config/mysqlConfig.js');
|
||||
const mysql = require('./config/mysqlConfig');
|
||||
const site = require('./config/siteConfig');
|
||||
const slack = require('./config/slackConfig.js');
|
||||
const database = require('./server/models');
|
||||
const localLoginStrategy = require('./server/passport/local-login.js');
|
||||
const localSignupStrategy = require('./server/passport/local-signup.js');
|
||||
const passport = require('./server/passport/');
|
||||
|
||||
const exports = {
|
||||
// Server,
|
||||
// Components,
|
||||
// Containers,
|
||||
// Pages,
|
||||
apiRoutes,
|
||||
config: {
|
||||
logger,
|
||||
mysql,
|
||||
site,
|
||||
slack,
|
||||
},
|
||||
database,
|
||||
passport: {
|
||||
localLoginStrategy,
|
||||
localSignupStrategy,
|
||||
},
|
||||
passport,
|
||||
};
|
||||
|
||||
module.exports = exports;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const Path = require('path');
|
||||
const nodeExternals = require('webpack-node-externals');
|
||||
const CLIENT_ROOT = Path.resolve(__dirname, 'client/');
|
||||
const CONFIG_ROOT = Path.resolve(__dirname, 'config/');
|
||||
const SERVER_ROOT = Path.resolve(__dirname, 'server/');
|
||||
|
||||
module.exports = {
|
||||
|
@ -36,6 +37,7 @@ module.exports = {
|
|||
resolve: {
|
||||
modules: [
|
||||
CLIENT_ROOT,
|
||||
CONFIG_ROOT,
|
||||
SERVER_ROOT,
|
||||
'node_modules',
|
||||
__dirname,
|
||||
|
|
Loading…
Reference in a new issue