From 60a74b51afce4edb0aea86aec9eb58f5eb805e12 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 6 Jun 2018 12:01:11 -0700 Subject: [PATCH] changed reducers etc to take configs directly via alias --- client/build/reducers/index.js | 17 +- client/build/reducers/publish.js | 200 +++++++++--------- client/build/reducers/site.js | 83 ++++---- client/src/reducers/index.js | 19 +- client/src/reducers/publish.js | 180 ++++++++-------- client/src/reducers/site.js | 82 ++++--- index.js | 180 +++++++++------- server/models/index.js | 9 +- .../models/utils/createDatabaseIfNotExists.js | 2 +- server/render/build/handlePageRender.js | 12 +- server/render/build/handleShowRender.js | 12 +- server/render/src/handlePageRender.jsx | 15 +- server/render/src/handleShowRender.jsx | 15 +- server/utils/configureLogging.js | 14 +- server/utils/configureSlack.js | 14 +- 15 files changed, 426 insertions(+), 428 deletions(-) diff --git a/client/build/reducers/index.js b/client/build/reducers/index.js index cccf793d..1602ea2e 100644 --- a/client/build/reducers/index.js +++ b/client/build/reducers/index.js @@ -19,15 +19,12 @@ var _channelCreate = _interopRequireDefault(require("./channelCreate")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var customizedReducers = function customizedReducers(siteConfig) { - return (0, _redux.combineReducers)({ - channel: _channel.default, - channelCreate: _channelCreate.default, - publish: (0, _publish.default)(siteConfig), - show: _show.default, - site: (0, _site.default)(siteConfig) - }); -}; +var _default = (0, _redux.combineReducers)({ + channel: _channel.default, + channelCreate: _channelCreate.default, + publish: _publish.default, + show: _show.default, + site: _site.default +}); -var _default = customizedReducers; exports.default = _default; \ No newline at end of file diff --git a/client/build/reducers/publish.js b/client/build/reducers/publish.js index a7ee6054..6e665be6 100644 --- a/client/build/reducers/publish.js +++ b/client/build/reducers/publish.js @@ -9,113 +9,115 @@ var actions = _interopRequireWildcard(require("../constants/publish_action_types var _publish_channel_select_states = require("../constants/publish_channel_select_states"); +var _siteConfig = _interopRequireDefault(require("@config/siteConfig")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } -var customizedPublishReducer = function customizedPublishReducer(siteConfig) { - // parse inputs - var disabledConfig = false; - var disabledMessageConfig = 'none'; - var thumbnailChannel = ''; - var thumbnailChannelId = ''; +// parse inputs +var disabledConfig = false; +var disabledMessageConfig = 'none'; +var thumbnailChannel = ''; +var thumbnailChannelId = ''; - if (siteConfig) { - if (siteConfig.publishing) { - disabledConfig = siteConfig.publishing.disabled; - disabledMessageConfig = siteConfig.publishing.disabledMessage; - thumbnailChannel = siteConfig.publishing.thumbnailChannel; - thumbnailChannelId = siteConfig.publishing.thumbnailChannelId; - } - } // create initial state +if (_siteConfig.default) { + if (_siteConfig.default.publishing) { + disabledConfig = _siteConfig.default.publishing.disabled; + disabledMessageConfig = _siteConfig.default.publishing.disabledMessage; + thumbnailChannel = _siteConfig.default.publishing.thumbnailChannel; + thumbnailChannelId = _siteConfig.default.publishing.thumbnailChannelId; + } +} // create initial state - var initialState = { - disabled: disabledConfig, - disabledMessage: disabledMessageConfig, - publishInChannel: false, - selectedChannel: _publish_channel_select_states.LOGIN, - showMetadataInputs: false, - status: { - status: null, - message: null - }, - error: { - file: null, - url: null, - channel: null - }, +var initialState = { + disabled: disabledConfig, + disabledMessage: disabledMessageConfig, + publishInChannel: false, + selectedChannel: _publish_channel_select_states.LOGIN, + showMetadataInputs: false, + status: { + status: null, + message: null + }, + error: { file: null, - claim: '', - metadata: { - title: '', - description: '', - license: '', - nsfw: false - }, - thumbnail: null, - thumbnailChannel: thumbnailChannel, - thumbnailChannelId: thumbnailChannelId - }; - return function () { - var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; - var action = arguments.length > 1 ? arguments[1] : undefined; - - switch (action.type) { - case actions.FILE_SELECTED: - return Object.assign({}, initialState, { - // note: clears to initial state - file: action.data - }); - - case actions.FILE_CLEAR: - return initialState; - - case actions.METADATA_UPDATE: - return Object.assign({}, state, { - metadata: Object.assign({}, state.metadata, _defineProperty({}, action.data.name, action.data.value)) - }); - - case actions.CLAIM_UPDATE: - return Object.assign({}, state, { - claim: action.data - }); - - case actions.SET_PUBLISH_IN_CHANNEL: - return Object.assign({}, state, { - publishInChannel: action.channel - }); - - case actions.PUBLISH_STATUS_UPDATE: - return Object.assign({}, state, { - status: action.data - }); - - case actions.ERROR_UPDATE: - return Object.assign({}, state, { - error: Object.assign({}, state.error, _defineProperty({}, action.data.name, action.data.value)) - }); - - case actions.SELECTED_CHANNEL_UPDATE: - return Object.assign({}, state, { - selectedChannel: action.data - }); - - case actions.TOGGLE_METADATA_INPUTS: - return Object.assign({}, state, { - showMetadataInputs: action.data - }); - - case actions.THUMBNAIL_NEW: - return Object.assign({}, state, { - thumbnail: action.data - }); - - default: - return state; - } - }; + url: null, + channel: null + }, + file: null, + claim: '', + metadata: { + title: '', + description: '', + license: '', + nsfw: false + }, + thumbnail: null, + thumbnailChannel: thumbnailChannel, + thumbnailChannelId: thumbnailChannelId +}; + +var _default = function _default() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; + var action = arguments.length > 1 ? arguments[1] : undefined; + + switch (action.type) { + case actions.FILE_SELECTED: + return Object.assign({}, initialState, { + // note: clears to initial state + file: action.data + }); + + case actions.FILE_CLEAR: + return initialState; + + case actions.METADATA_UPDATE: + return Object.assign({}, state, { + metadata: Object.assign({}, state.metadata, _defineProperty({}, action.data.name, action.data.value)) + }); + + case actions.CLAIM_UPDATE: + return Object.assign({}, state, { + claim: action.data + }); + + case actions.SET_PUBLISH_IN_CHANNEL: + return Object.assign({}, state, { + publishInChannel: action.channel + }); + + case actions.PUBLISH_STATUS_UPDATE: + return Object.assign({}, state, { + status: action.data + }); + + case actions.ERROR_UPDATE: + return Object.assign({}, state, { + error: Object.assign({}, state.error, _defineProperty({}, action.data.name, action.data.value)) + }); + + case actions.SELECTED_CHANNEL_UPDATE: + return Object.assign({}, state, { + selectedChannel: action.data + }); + + case actions.TOGGLE_METADATA_INPUTS: + return Object.assign({}, state, { + showMetadataInputs: action.data + }); + + case actions.THUMBNAIL_NEW: + return Object.assign({}, state, { + thumbnail: action.data + }); + + default: + return state; + } }; -var _default = customizedPublishReducer; exports.default = _default; \ No newline at end of file diff --git a/client/build/reducers/site.js b/client/build/reducers/site.js index ea6c37f1..a11f58bc 100644 --- a/client/build/reducers/site.js +++ b/client/build/reducers/site.js @@ -5,50 +5,49 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = void 0; -var customizedSiteReducer = function customizedSiteReducer(siteConfig) { - var initialState = {}; +var _siteConfig = _interopRequireDefault(require("@config/siteConfig")); - if (siteConfig) { - var googleAnalyticsId = siteConfig.analytics.googleId, - _siteConfig$assetDefa = siteConfig.assetDefaults, - defaultThumbnail = _siteConfig$assetDefa.thumbnail, - defaultDescription = _siteConfig$assetDefa.description, - _siteConfig$details = siteConfig.details, - description = _siteConfig$details.description, - host = _siteConfig$details.host, - title = _siteConfig$details.title, - twitter = _siteConfig$details.twitter; - initialState = { - description: description, - googleAnalyticsId: googleAnalyticsId, - host: host, - title: title, - twitter: twitter, - defaultDescription: defaultDescription, - defaultThumbnail: defaultThumbnail - }; - } else { - initialState = { - description: 'default description', - googleAnalyticsId: 'default google id', - host: 'default host', - title: 'default title', - twitter: 'default twitter', - defaultDescription: 'default description', - defaultThumbnail: 'default thumbnail' - }; - } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - return function () { - var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; - var action = arguments.length > 1 ? arguments[1] : undefined; - - switch (action.type) { - default: - return state; - } - }; +var initialState = { + description: 'default description', + googleAnalyticsId: 'default google id', + host: 'default host', + title: 'default title', + twitter: 'default twitter', + defaultDescription: 'default description', + defaultThumbnail: 'default thumbnail' +}; + +if (_siteConfig.default) { + var googleAnalyticsId = _siteConfig.default.analytics.googleId, + _siteConfig$assetDefa = _siteConfig.default.assetDefaults, + defaultThumbnail = _siteConfig$assetDefa.thumbnail, + defaultDescription = _siteConfig$assetDefa.description, + _siteConfig$details = _siteConfig.default.details, + description = _siteConfig$details.description, + host = _siteConfig$details.host, + title = _siteConfig$details.title, + twitter = _siteConfig$details.twitter; + initialState = { + description: description, + googleAnalyticsId: googleAnalyticsId, + host: host, + title: title, + twitter: twitter, + defaultDescription: defaultDescription, + defaultThumbnail: defaultThumbnail + }; +} + +var _default = function _default() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; + var action = arguments.length > 1 ? arguments[1] : undefined; + + switch (action.type) { + default: + return state; + } }; -var _default = customizedSiteReducer; exports.default = _default; \ No newline at end of file diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index 794888e1..99b725df 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,18 +1,15 @@ import { combineReducers } from 'redux'; + import PublishReducer from './publish'; import ChannelReducer from './channel'; import ShowReducer from './show'; import SiteReducer from './site'; import ChannelCreateReducer from './channelCreate'; -const customizedReducers = (siteConfig) => { - return combineReducers({ - channel : ChannelReducer, - channelCreate: ChannelCreateReducer, - publish : PublishReducer(siteConfig), - show : ShowReducer, - site : SiteReducer(siteConfig), - }) -}; - -export default customizedReducers; +export default combineReducers({ + channel : ChannelReducer, + channelCreate: ChannelCreateReducer, + publish : PublishReducer, + show : ShowReducer, + site : SiteReducer, +}); diff --git a/client/src/reducers/publish.js b/client/src/reducers/publish.js index 6138cbe9..ad64b3f3 100644 --- a/client/src/reducers/publish.js +++ b/client/src/reducers/publish.js @@ -1,96 +1,96 @@ import * as actions from '../constants/publish_action_types'; import { LOGIN } from '../constants/publish_channel_select_states'; -const customizedPublishReducer = (siteConfig) => { - // parse inputs - let disabledConfig = false; - let disabledMessageConfig = 'none'; - let thumbnailChannel = ''; - let thumbnailChannelId = ''; - if (siteConfig) { - if (siteConfig.publishing) { - disabledConfig = siteConfig.publishing.disabled; - disabledMessageConfig = siteConfig.publishing.disabledMessage; - thumbnailChannel = siteConfig.publishing.thumbnailChannel; - thumbnailChannelId = siteConfig.publishing.thumbnailChannelId; - } +import siteConfig from '@config/siteConfig'; + +// parse inputs +let disabledConfig = false; +let disabledMessageConfig = 'none'; +let thumbnailChannel = ''; +let thumbnailChannelId = ''; +if (siteConfig) { + if (siteConfig.publishing) { + disabledConfig = siteConfig.publishing.disabled; + disabledMessageConfig = siteConfig.publishing.disabledMessage; + thumbnailChannel = siteConfig.publishing.thumbnailChannel; + thumbnailChannelId = siteConfig.publishing.thumbnailChannelId; } - // create initial state - const initialState = { - disabled : disabledConfig, - disabledMessage : disabledMessageConfig, - publishInChannel : false, - selectedChannel : LOGIN, - showMetadataInputs: false, - status : { - status : null, - message: null, - }, - error: { - file : null, - url : null, - channel: null, - }, - file : null, - claim : '', - metadata: { - title : '', - description: '', - license : '', - nsfw : false, - }, - thumbnail: null, - thumbnailChannel, - thumbnailChannelId, - }; - return (state = initialState, action) => { - switch (action.type) { - case actions.FILE_SELECTED: - return Object.assign({}, initialState, { // note: clears to initial state - file: action.data, - }); - case actions.FILE_CLEAR: - return initialState; - case actions.METADATA_UPDATE: - return Object.assign({}, state, { - metadata: Object.assign({}, state.metadata, { - [action.data.name]: action.data.value, - }), - }); - case actions.CLAIM_UPDATE: - return Object.assign({}, state, { - claim: action.data, - }); - case actions.SET_PUBLISH_IN_CHANNEL: - return Object.assign({}, state, { - publishInChannel: action.channel, - }); - case actions.PUBLISH_STATUS_UPDATE: - return Object.assign({}, state, { - status: action.data, - }); - case actions.ERROR_UPDATE: - return Object.assign({}, state, { - error: Object.assign({}, state.error, { - [action.data.name]: action.data.value, - }), - }); - case actions.SELECTED_CHANNEL_UPDATE: - return Object.assign({}, state, { - selectedChannel: action.data, - }); - case actions.TOGGLE_METADATA_INPUTS: - return Object.assign({}, state, { - showMetadataInputs: action.data, - }); - case actions.THUMBNAIL_NEW: - return Object.assign({}, state, { - thumbnail: action.data, - }); - default: - return state; - } - }; +} + +// create initial state +const initialState = { + disabled : disabledConfig, + disabledMessage : disabledMessageConfig, + publishInChannel : false, + selectedChannel : LOGIN, + showMetadataInputs: false, + status : { + status : null, + message: null, + }, + error: { + file : null, + url : null, + channel: null, + }, + file : null, + claim : '', + metadata: { + title : '', + description: '', + license : '', + nsfw : false, + }, + thumbnail: null, + thumbnailChannel, + thumbnailChannelId, }; -export default customizedPublishReducer; +export default (state = initialState, action) => { + switch (action.type) { + case actions.FILE_SELECTED: + return Object.assign({}, initialState, { // note: clears to initial state + file: action.data, + }); + case actions.FILE_CLEAR: + return initialState; + case actions.METADATA_UPDATE: + return Object.assign({}, state, { + metadata: Object.assign({}, state.metadata, { + [action.data.name]: action.data.value, + }), + }); + case actions.CLAIM_UPDATE: + return Object.assign({}, state, { + claim: action.data, + }); + case actions.SET_PUBLISH_IN_CHANNEL: + return Object.assign({}, state, { + publishInChannel: action.channel, + }); + case actions.PUBLISH_STATUS_UPDATE: + return Object.assign({}, state, { + status: action.data, + }); + case actions.ERROR_UPDATE: + return Object.assign({}, state, { + error: Object.assign({}, state.error, { + [action.data.name]: action.data.value, + }), + }); + case actions.SELECTED_CHANNEL_UPDATE: + return Object.assign({}, state, { + selectedChannel: action.data, + }); + case actions.TOGGLE_METADATA_INPUTS: + return Object.assign({}, state, { + showMetadataInputs: action.data, + }); + case actions.THUMBNAIL_NEW: + return Object.assign({}, state, { + thumbnail: action.data, + }); + default: + return state; + } +}; diff --git a/client/src/reducers/site.js b/client/src/reducers/site.js index 5a1b1584..1c3bbbf2 100644 --- a/client/src/reducers/site.js +++ b/client/src/reducers/site.js @@ -1,48 +1,46 @@ -const customizedSiteReducer = (siteConfig) => { - let initialState = {}; - if (siteConfig) { - const { - analytics: { - googleId: googleAnalyticsId, - }, - assetDefaults: { - thumbnail: defaultThumbnail, - description: defaultDescription, - }, - details: { - description, - host, - title, - twitter, - }, - } = siteConfig; +import siteConfig from '@config/siteConfig'; - initialState = { +let initialState = { + description : 'default description', + googleAnalyticsId : 'default google id', + host : 'default host', + title : 'default title', + twitter : 'default twitter', + defaultDescription: 'default description', + defaultThumbnail : 'default thumbnail', +}; + +if (siteConfig) { + const { + analytics: { + googleId: googleAnalyticsId, + }, + assetDefaults: { + thumbnail: defaultThumbnail, + description: defaultDescription, + }, + details: { description, - googleAnalyticsId, host, title, twitter, - defaultDescription, - defaultThumbnail, - }; - } else { - initialState = { - description : 'default description', - googleAnalyticsId : 'default google id', - host : 'default host', - title : 'default title', - twitter : 'default twitter', - defaultDescription: 'default description', - defaultThumbnail : 'default thumbnail', - }; - } - return (state = initialState, action) => { - switch (action.type) { - default: - return state; - } - }; -}; + }, + } = siteConfig; -export default customizedSiteReducer; + initialState = { + description, + googleAnalyticsId, + host, + title, + twitter, + defaultDescription, + defaultThumbnail, + }; +} + +export default (state = initialState, action) => { + switch (action.type) { + default: + return state; + } +}; diff --git a/index.js b/index.js index 63a1d2b4..7910bbf2 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,10 @@ +// set up aliasing +const moduleAlias = require('module-alias'); +const createModuleAliases = require('./server/utils/createModuleAliases.js'); +const customAliases = createModuleAliases(); +console.log('custom aliases', customAliases); +moduleAlias.addAliases(customAliases); + // load modules const express = require('express'); const bodyParser = require('body-parser'); @@ -8,104 +15,119 @@ const cookieSession = require('cookie-session'); const http = require('http'); const logger = require('winston'); const Path = require('path'); -const moduleAlias = require('module-alias'); // load local modules +const db = require('./server/models'); const requestLogger = require('./server/middleware/requestLogger.js'); const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js'); const { getWalletBalance } = require('./server/lbrynet'); -const db = require('./server/models'); const configureLogging = require('./server/utils/configureLogging.js'); const configureSlack = require('./server/utils/configureSlack.js'); const speechPassport = require('./server/speechPassport'); -const createModuleAliases = require('./utils/createModuleAliases.js'); -// set up aliasing -const customAliases = createModuleAliases(); -logger.debug('custom aliases', customAliases); -moduleAlias.addAliases(customAliases); - -// load aliased modules +// test configs const siteConfig = require('@config/siteConfig'); +console.log('siteConfig:', siteConfig); +const mysqlConfig = require('@config/mysqlConfig'); +console.log('mysqlConfig:', mysqlConfig); +const slackConfig = require('@config/slackConfig'); +console.log('slackConfig:', slackConfig); +const loggerConfig = require('@config/loggerConfig'); +console.log('loggerConfig:', loggerConfig); + const PORT = siteConfig.details.port; -const startServer = () => { - // configure logging - configureLogging(); +function Server () { + this.initialize = () => { + // configure logging + configureLogging(); + // configure slack logging + configureSlack(); + }; + this.createApp = () => { + /* create app */ + const app = express(); - // configure slack logging - configureSlack(); + // trust the proxy to get ip address for us + app.enable('trust proxy'); - /* create app */ - const app = express(); + // set HTTP headers to protect against well-known web vulnerabilties + app.use(helmet()); - // trust the proxy to get ip address for us - app.enable('trust proxy'); + // 'express.static' to serve static files from public directory + const publicPath = Path.resolve(process.cwd(), 'public'); + app.use(express.static(publicPath)); + logger.info(`serving static files from default static path at ${publicPath}.`); - // set HTTP headers to protect against well-known web vulnerabilties - app.use(helmet()); + // 'body parser' for parsing application/json + app.use(bodyParser.json()); - // 'express.static' to serve static files from public directory - const publicPath = Path.resolve(process.cwd(), 'public'); - app.use(express.static(publicPath)); - logger.info(`serving static files from default static path at ${publicPath}.`); + // 'body parser' for parsing application/x-www-form-urlencoded + app.use(bodyParser.urlencoded({ extended: true })); - // 'body parser' for parsing application/json - app.use(bodyParser.json()); + // add custom middleware (note: build out to accept dynamically use what is in server/middleware/ + app.use(requestLogger); - // 'body parser' for parsing application/x-www-form-urlencoded - app.use(bodyParser.urlencoded({ extended: true })); + // initialize passport + const sessionKey = siteConfig.auth.sessionKey; + app.use(cookieSession({ + name : 'session', + keys : [sessionKey], + })); + app.use(speechPassport.initialize()); + app.use(speechPassport.session()); - // add custom middleware (note: build out to accept dynamically use what is in server/middleware/ - app.use(requestLogger); - - // initialize passport - const sessionKey = siteConfig.auth.sessionKey; - app.use(cookieSession({ - name : 'session', - keys : [sessionKey], - })); - app.use(speechPassport.initialize()); - app.use(speechPassport.session()); - - // configure handlebars & register it with express app - const hbs = expressHandlebars.create({ - defaultLayout: 'embed', - handlebars : Handlebars, - }); - app.engine('handlebars', hbs.engine); - app.set('view engine', 'handlebars'); - - // set the routes on the app - require('./server/routes/auth')(app); - require('./server/routes/api')(app); - require('./server/routes/pages')(app); - require('./server/routes/assets')(app); - require('./server/routes/fallback')(app); - - /* create server */ - const server = http.Server(app); - - /* start the server */ - createDatabaseIfNotExists() - .then(() => { - return getWalletBalance(); - }) - .then(balance => { - logger.info('starting LBC balance:', balance); - db.sequelize.sync(); - server.listen(PORT, () => { - logger.info(`Server is listening on PORT ${PORT}`); - }); - }) - .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); + // configure handlebars & register it with express app + const hbs = expressHandlebars.create({ + defaultLayout: 'embed', + handlebars : Handlebars, }); -}; + app.engine('handlebars', hbs.engine); + app.set('view engine', 'handlebars'); -module.exports = startServer; + // set the routes on the app + require('./server/routes/auth')(app); + require('./server/routes/api')(app); + require('./server/routes/pages')(app); + require('./server/routes/assets')(app); + require('./server/routes/fallback')(app); + + this.app = app; + }; + this.createServer = () => { + /* create server */ + this.server = http.Server(this.app); + }; + this.syncDatabase = () => { + return createDatabaseIfNotExists() + .then(() => { + db.sequelize.sync(); + }) + }; + this.start = () => { + this.initialize(); + this.createApp(); + this.createServer(); + /* start the server */ + Promise.all([ + this.syncDatabase(), + getWalletBalance(), + ]) + .then(([syncResult, walletBalance]) => { + logger.info('starting LBC balance:', walletBalance); + return this.server.listen(PORT, () => { + logger.info(`Server is listening on PORT ${PORT}`); + }) + }) + .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); + }); + }; +} + +module.exports = Server; diff --git a/server/models/index.js b/server/models/index.js index 5795f782..e2011bc8 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -1,3 +1,6 @@ +const Sequelize = require('sequelize'); +const logger = require('winston'); + const Certificate = require('./certificate.js'); const Channel = require('./channel.js'); const Claim = require('./claim.js'); @@ -6,10 +9,10 @@ const Request = require('./request.js'); const User = require('./user.js'); const Blocked = require('./blocked.js'); -const Sequelize = require('sequelize'); -const logger = require('winston'); - const {database, username, password} = require('@config/mysqlConfig'); +if (!database || !username || !password) { + logger.warn('missing database, user, or password from mysqlConfig'); +} // set sequelize options const sequelize = new Sequelize(database, username, password, { diff --git a/server/models/utils/createDatabaseIfNotExists.js b/server/models/utils/createDatabaseIfNotExists.js index e7ae8faa..7349b492 100644 --- a/server/models/utils/createDatabaseIfNotExists.js +++ b/server/models/utils/createDatabaseIfNotExists.js @@ -1,7 +1,7 @@ const Sequelize = require('sequelize'); +const {database, username, password} = require('@config/mysqlConfig'); const createDatabaseIfNotExists = () => { - const {database, username, password} = require('@config/mysqlConfig'); const sequelize = new Sequelize('', username, password, { dialect : 'mysql', logging : false, diff --git a/server/render/build/handlePageRender.js b/server/render/build/handlePageRender.js index ea51a1c0..0e5dd197 100644 --- a/server/render/build/handlePageRender.js +++ b/server/render/build/handlePageRender.js @@ -22,23 +22,17 @@ var _reactHelmet = _interopRequireDefault(require("react-helmet")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var siteConfig = require('@config/siteConfig'); - module.exports = function (req, res) { - var context = {}; // customize the reducer by passing in intial state configs + var context = {}; // create a new Redux store instance - var MyReducers = (0, _reducers.default)(siteConfig); - var MyApp = _app.default; - var MyGAListener = (0, _GAListener.default)(siteConfig); // create a new Redux store instance - - var store = (0, _redux.createStore)(MyReducers); // render component to a string + var store = (0, _redux.createStore)(_reducers.default); // render component to a string var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, { store: store }, _react.default.createElement(_reactRouterDom.StaticRouter, { location: req.url, context: context - }, _react.default.createElement(MyGAListener, null, _react.default.createElement(MyApp, null))))); // get head tags from helmet + }, _react.default.createElement(_GAListener.default, null, _react.default.createElement(_app.default, null))))); // get head tags from helmet var helmet = _reactHelmet.default.renderStatic(); // check for a redirect diff --git a/server/render/build/handleShowRender.js b/server/render/build/handleShowRender.js index 57327785..ac1ac7cc 100644 --- a/server/render/build/handleShowRender.js +++ b/server/render/build/handleShowRender.js @@ -30,8 +30,6 @@ var _reactHelmet = _interopRequireDefault(require("react-helmet")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var siteConfig = require('@config/siteConfig'); - var returnSagaWithParams = function returnSagaWithParams(saga, params) { return ( /*#__PURE__*/ @@ -54,16 +52,12 @@ var returnSagaWithParams = function returnSagaWithParams(saga, params) { }; module.exports = function (req, res) { - var context = {}; // configure the reducers by passing initial state configs - - var MyReducers = (0, _reducers.default)(siteConfig); - var MyApp = _app.default; - var MyGAListener = (0, _GAListener.default)(siteConfig); // create and apply middleware + var context = {}; // create and apply middleware var sagaMiddleware = (0, _reduxSaga.default)(); var middleware = (0, _redux.applyMiddleware)(sagaMiddleware); // create a new Redux store instance - var store = (0, _redux.createStore)(MyReducers, middleware); // create saga + var store = (0, _redux.createStore)(_reducers.default, middleware); // create saga var action = _actions.default.onHandleShowPageUri(req.params); @@ -76,7 +70,7 @@ module.exports = function (req, res) { }, _react.default.createElement(_reactRouterDom.StaticRouter, { location: req.url, context: context - }, _react.default.createElement(MyGAListener, null, _react.default.createElement(MyApp, null))))); // get head tags from helmet + }, _react.default.createElement(_GAListener.default, null, _react.default.createElement(_app.default, null))))); // get head tags from helmet var helmet = _reactHelmet.default.renderStatic(); // check for a redirect diff --git a/server/render/src/handlePageRender.jsx b/server/render/src/handlePageRender.jsx index ec9e7eb7..9f9320d6 100644 --- a/server/render/src/handlePageRender.jsx +++ b/server/render/src/handlePageRender.jsx @@ -9,26 +9,19 @@ import App from '@app'; import renderFullPage from '../renderFullPage.js'; import Helmet from 'react-helmet'; -const siteConfig = require('@config/siteConfig'); - module.exports = (req, res) => { let context = {}; - // customize the reducer by passing in intial state configs - const MyReducers = Reducers(siteConfig); - const MyApp = App; - const MyGAListener = GAListener(siteConfig); - // create a new Redux store instance - const store = createStore(MyReducers); + const store = createStore(Reducers); // render component to a string const html = renderToString( - - - + + + ); diff --git a/server/render/src/handleShowRender.jsx b/server/render/src/handleShowRender.jsx index a1ea0172..5f48afe4 100644 --- a/server/render/src/handleShowRender.jsx +++ b/server/render/src/handleShowRender.jsx @@ -13,8 +13,6 @@ import Sagas from '@sagas'; import Actions from '@actions'; import Helmet from 'react-helmet'; -const siteConfig = require('@config/siteConfig'); - const returnSagaWithParams = (saga, params) => { return function * () { yield call(saga, params); @@ -24,17 +22,12 @@ const returnSagaWithParams = (saga, params) => { module.exports = (req, res) => { let context = {}; - // configure the reducers by passing initial state configs - const MyReducers = Reducers(siteConfig); - const MyApp = App; - const MyGAListener = GAListener(siteConfig); - // create and apply middleware const sagaMiddleware = createSagaMiddleware(); const middleware = applyMiddleware(sagaMiddleware); // create a new Redux store instance - const store = createStore(MyReducers, middleware); + const store = createStore(Reducers, middleware); // create saga const action = Actions.onHandleShowPageUri(req.params); @@ -49,9 +42,9 @@ module.exports = (req, res) => { const html = renderToString( - - - + + + ); diff --git a/server/utils/configureLogging.js b/server/utils/configureLogging.js index e877d89f..49af20bb 100644 --- a/server/utils/configureLogging.js +++ b/server/utils/configureLogging.js @@ -1,17 +1,21 @@ const logger = require('winston'); -const { logLevel } = require('@config/loggerConfig'); +const config = require('@config/loggerConfig'); +const { logLevel } = config; function configureLogging () { - if (!logLevel) { - return logger.warn('No logLevel config received.'); - } logger.info('configuring winston logger...'); + if (!config) { + return logger.warn('No logger config found'); + } + if (!logLevel) { + logger.warn('No logLevel found in config.'); + } // configure the winston logger logger.configure({ transports: [ new (logger.transports.Console)({ - level : this.logLevel, + level : logLevel || 'debug', timestamp : false, colorize : true, prettyPrint : true, diff --git a/server/utils/configureSlack.js b/server/utils/configureSlack.js index 88806acc..feef1122 100644 --- a/server/utils/configureSlack.js +++ b/server/utils/configureSlack.js @@ -1,19 +1,17 @@ const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook; const logger = require('winston'); -const config = require('@config/loggerConfig'); +const config = require('@config/slackConfig'); +const {slackWebHook, slackErrorChannel, slackInfoChannel} = config; function configureSlack () { + logger.info('configuring slack logger...'); if (!config) { return logger.warn('No slack config found'); } - const {slackWebHook, slackErrorChannel, slackInfoChannel} = config; - // update variables - logger.info('configuring slack logger...'); - // update slack webhook settings if (!slackWebHook) { - return logger.warn('Slack logging is not enabled because no slackWebHook config var provided.'); + return logger.info('Slack logging is not enabled because no slackWebHook config var provided.'); } // add a transport for errors to slack if (slackErrorChannel) { @@ -25,6 +23,8 @@ function configureSlack () { username : 'spee.ch', iconEmoji : ':face_with_head_bandage:', }); + } else { + logger.warn('No slack error channel logging set up'); } // add a transport for info in slack if (slackInfoChannel) { @@ -36,6 +36,8 @@ function configureSlack () { username : 'spee.ch', iconEmoji : ':nerd_face:', }); + } else { + logger.warn('No slack info channel logging set up'); } // send test messages logger.info('Slack logging is online.');