Fix configs loading #470

Merged
bones7242 merged 15 commits from fix-configs-loading into master 2018-06-07 19:40:01 +02:00
15 changed files with 426 additions and 428 deletions
Showing only changes of commit 60a74b51af - Show all commits

View file

@ -19,15 +19,12 @@ var _channelCreate = _interopRequireDefault(require("./channelCreate"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var customizedReducers = function customizedReducers(siteConfig) { var _default = (0, _redux.combineReducers)({
return (0, _redux.combineReducers)({ channel: _channel.default,
channel: _channel.default, channelCreate: _channelCreate.default,
channelCreate: _channelCreate.default, publish: _publish.default,
publish: (0, _publish.default)(siteConfig), show: _show.default,
show: _show.default, site: _site.default
site: (0, _site.default)(siteConfig) });
});
};
var _default = customizedReducers;
exports.default = _default; exports.default = _default;

View file

@ -9,113 +9,115 @@ var actions = _interopRequireWildcard(require("../constants/publish_action_types
var _publish_channel_select_states = require("../constants/publish_channel_select_states"); 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 _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; } 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
// parse inputs var disabledConfig = false;
var disabledConfig = false; var disabledMessageConfig = 'none';
var disabledMessageConfig = 'none'; var thumbnailChannel = '';
var thumbnailChannel = ''; var thumbnailChannelId = '';
var thumbnailChannelId = '';
if (siteConfig) { if (_siteConfig.default) {
if (siteConfig.publishing) { if (_siteConfig.default.publishing) {
disabledConfig = siteConfig.publishing.disabled; disabledConfig = _siteConfig.default.publishing.disabled;
disabledMessageConfig = siteConfig.publishing.disabledMessage; disabledMessageConfig = _siteConfig.default.publishing.disabledMessage;
thumbnailChannel = siteConfig.publishing.thumbnailChannel; thumbnailChannel = _siteConfig.default.publishing.thumbnailChannel;
thumbnailChannelId = siteConfig.publishing.thumbnailChannelId; thumbnailChannelId = _siteConfig.default.publishing.thumbnailChannelId;
} }
} // create initial state } // create initial state
var initialState = { var initialState = {
disabled: disabledConfig, disabled: disabledConfig,
disabledMessage: disabledMessageConfig, disabledMessage: disabledMessageConfig,
publishInChannel: false, publishInChannel: false,
selectedChannel: _publish_channel_select_states.LOGIN, selectedChannel: _publish_channel_select_states.LOGIN,
showMetadataInputs: false, showMetadataInputs: false,
status: { status: {
status: null, status: null,
message: null message: null
}, },
error: { error: {
file: null,
url: null,
channel: null
},
file: null, file: null,
claim: '', url: null,
metadata: { channel: null
title: '', },
description: '', file: null,
license: '', claim: '',
nsfw: false metadata: {
}, title: '',
thumbnail: null, description: '',
thumbnailChannel: thumbnailChannel, license: '',
thumbnailChannelId: thumbnailChannelId nsfw: false
}; },
return function () { thumbnail: null,
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; thumbnailChannel: thumbnailChannel,
var action = arguments.length > 1 ? arguments[1] : undefined; thumbnailChannelId: thumbnailChannelId
};
switch (action.type) {
case actions.FILE_SELECTED: var _default = function _default() {
return Object.assign({}, initialState, { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
// note: clears to initial state var action = arguments.length > 1 ? arguments[1] : undefined;
file: action.data
}); switch (action.type) {
case actions.FILE_SELECTED:
case actions.FILE_CLEAR: return Object.assign({}, initialState, {
return initialState; // note: clears to initial state
file: action.data
case actions.METADATA_UPDATE: });
return Object.assign({}, state, {
metadata: Object.assign({}, state.metadata, _defineProperty({}, action.data.name, action.data.value)) case actions.FILE_CLEAR:
}); return initialState;
case actions.CLAIM_UPDATE: case actions.METADATA_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
claim: action.data metadata: Object.assign({}, state.metadata, _defineProperty({}, action.data.name, action.data.value))
}); });
case actions.SET_PUBLISH_IN_CHANNEL: case actions.CLAIM_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
publishInChannel: action.channel claim: action.data
}); });
case actions.PUBLISH_STATUS_UPDATE: case actions.SET_PUBLISH_IN_CHANNEL:
return Object.assign({}, state, { return Object.assign({}, state, {
status: action.data publishInChannel: action.channel
}); });
case actions.ERROR_UPDATE: case actions.PUBLISH_STATUS_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
error: Object.assign({}, state.error, _defineProperty({}, action.data.name, action.data.value)) status: action.data
}); });
case actions.SELECTED_CHANNEL_UPDATE: case actions.ERROR_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
selectedChannel: action.data error: Object.assign({}, state.error, _defineProperty({}, action.data.name, action.data.value))
}); });
case actions.TOGGLE_METADATA_INPUTS: case actions.SELECTED_CHANNEL_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
showMetadataInputs: action.data selectedChannel: action.data
}); });
case actions.THUMBNAIL_NEW: case actions.TOGGLE_METADATA_INPUTS:
return Object.assign({}, state, { return Object.assign({}, state, {
thumbnail: action.data showMetadataInputs: action.data
}); });
default: case actions.THUMBNAIL_NEW:
return state; return Object.assign({}, state, {
} thumbnail: action.data
}; });
default:
return state;
}
}; };
var _default = customizedPublishReducer;
exports.default = _default; exports.default = _default;

View file

@ -5,50 +5,49 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = void 0; exports.default = void 0;
var customizedSiteReducer = function customizedSiteReducer(siteConfig) { var _siteConfig = _interopRequireDefault(require("@config/siteConfig"));
var initialState = {};
if (siteConfig) { function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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'
};
}
return function () { var initialState = {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; description: 'default description',
var action = arguments.length > 1 ? arguments[1] : undefined; googleAnalyticsId: 'default google id',
host: 'default host',
switch (action.type) { title: 'default title',
default: twitter: 'default twitter',
return state; 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; exports.default = _default;

View file

@ -1,18 +1,15 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import PublishReducer from './publish'; import PublishReducer from './publish';
import ChannelReducer from './channel'; import ChannelReducer from './channel';
import ShowReducer from './show'; import ShowReducer from './show';
import SiteReducer from './site'; import SiteReducer from './site';
import ChannelCreateReducer from './channelCreate'; import ChannelCreateReducer from './channelCreate';
const customizedReducers = (siteConfig) => { export default combineReducers({
return combineReducers({ channel : ChannelReducer,
channel : ChannelReducer, channelCreate: ChannelCreateReducer,
channelCreate: ChannelCreateReducer, publish : PublishReducer,
publish : PublishReducer(siteConfig), show : ShowReducer,
show : ShowReducer, site : SiteReducer,
site : SiteReducer(siteConfig), });
})
};
export default customizedReducers;

View file

@ -1,96 +1,96 @@
import * as actions from '../constants/publish_action_types'; import * as actions from '../constants/publish_action_types';
import { LOGIN } from '../constants/publish_channel_select_states'; import { LOGIN } from '../constants/publish_channel_select_states';
const customizedPublishReducer = (siteConfig) => { import siteConfig from '@config/siteConfig';
// parse inputs
let disabledConfig = false; // parse inputs
let disabledMessageConfig = 'none'; let disabledConfig = false;
let thumbnailChannel = ''; let disabledMessageConfig = 'none';
let thumbnailChannelId = ''; let thumbnailChannel = '';
if (siteConfig) { let thumbnailChannelId = '';
if (siteConfig.publishing) { if (siteConfig) {
disabledConfig = siteConfig.publishing.disabled; if (siteConfig.publishing) {
disabledMessageConfig = siteConfig.publishing.disabledMessage; disabledConfig = siteConfig.publishing.disabled;
thumbnailChannel = siteConfig.publishing.thumbnailChannel; disabledMessageConfig = siteConfig.publishing.disabledMessage;
thumbnailChannelId = siteConfig.publishing.thumbnailChannelId; thumbnailChannel = siteConfig.publishing.thumbnailChannel;
} thumbnailChannelId = siteConfig.publishing.thumbnailChannelId;
} }
// create initial state }
const initialState = {
disabled : disabledConfig, // create initial state
disabledMessage : disabledMessageConfig, const initialState = {
publishInChannel : false, disabled : disabledConfig,
selectedChannel : LOGIN, disabledMessage : disabledMessageConfig,
showMetadataInputs: false, publishInChannel : false,
status : { selectedChannel : LOGIN,
status : null, showMetadataInputs: false,
message: null, status : {
}, status : null,
error: { message: null,
file : null, },
url : null, error: {
channel: null, file : null,
}, url : null,
file : null, channel: null,
claim : '', },
metadata: { file : null,
title : '', claim : '',
description: '', metadata: {
license : '', title : '',
nsfw : false, description: '',
}, license : '',
thumbnail: null, nsfw : false,
thumbnailChannel, },
thumbnailChannelId, thumbnail: null,
}; thumbnailChannel,
return (state = initialState, action) => { thumbnailChannelId,
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;
}
};
}; };
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;
}
};

View file

@ -1,48 +1,46 @@
const customizedSiteReducer = (siteConfig) => { import siteConfig from '@config/siteConfig';
let initialState = {};
if (siteConfig) {
const {
analytics: {
googleId: googleAnalyticsId,
},
assetDefaults: {
thumbnail: defaultThumbnail,
description: defaultDescription,
},
details: {
description,
host,
title,
twitter,
},
} = 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, description,
googleAnalyticsId,
host, host,
title, title,
twitter, twitter,
defaultDescription, },
defaultThumbnail, } = siteConfig;
};
} 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;
}
};
};
export default customizedSiteReducer; initialState = {
description,
googleAnalyticsId,
host,
title,
twitter,
defaultDescription,
defaultThumbnail,
};
}
export default (state = initialState, action) => {
switch (action.type) {
default:
return state;
}
};

180
index.js
View file

@ -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 // load modules
const express = require('express'); const express = require('express');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
@ -8,104 +15,119 @@ const cookieSession = require('cookie-session');
const http = require('http'); const http = require('http');
const logger = require('winston'); const logger = require('winston');
const Path = require('path'); const Path = require('path');
const moduleAlias = require('module-alias');
// load local modules // load local modules
const db = require('./server/models');
const requestLogger = require('./server/middleware/requestLogger.js'); const requestLogger = require('./server/middleware/requestLogger.js');
const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js'); const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js');
const { getWalletBalance } = require('./server/lbrynet'); const { getWalletBalance } = require('./server/lbrynet');
const db = require('./server/models');
const configureLogging = require('./server/utils/configureLogging.js'); const configureLogging = require('./server/utils/configureLogging.js');
const configureSlack = require('./server/utils/configureSlack.js'); const configureSlack = require('./server/utils/configureSlack.js');
const speechPassport = require('./server/speechPassport'); const speechPassport = require('./server/speechPassport');
const createModuleAliases = require('./utils/createModuleAliases.js');
// set up aliasing // test configs
const customAliases = createModuleAliases();
logger.debug('custom aliases', customAliases);
moduleAlias.addAliases(customAliases);
// load aliased modules
const siteConfig = require('@config/siteConfig'); 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 PORT = siteConfig.details.port;
const startServer = () => { function Server () {
// configure logging this.initialize = () => {
configureLogging(); // configure logging
configureLogging();
// configure slack logging
configureSlack();
};
this.createApp = () => {
/* create app */
const app = express();
// configure slack logging // trust the proxy to get ip address for us
configureSlack(); app.enable('trust proxy');
/* create app */ // set HTTP headers to protect against well-known web vulnerabilties
const app = express(); app.use(helmet());
// trust the proxy to get ip address for us // 'express.static' to serve static files from public directory
app.enable('trust proxy'); 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 // 'body parser' for parsing application/json
app.use(helmet()); app.use(bodyParser.json());
// 'express.static' to serve static files from public directory // 'body parser' for parsing application/x-www-form-urlencoded
const publicPath = Path.resolve(process.cwd(), 'public'); app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(publicPath));
logger.info(`serving static files from default static path at ${publicPath}.`);
// 'body parser' for parsing application/json // add custom middleware (note: build out to accept dynamically use what is in server/middleware/
app.use(bodyParser.json()); app.use(requestLogger);
// 'body parser' for parsing application/x-www-form-urlencoded // initialize passport
app.use(bodyParser.urlencoded({ extended: true })); 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/ // configure handlebars & register it with express app
app.use(requestLogger); const hbs = expressHandlebars.create({
defaultLayout: 'embed',
// initialize passport handlebars : Handlebars,
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);
}); });
}; 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;

View file

@ -1,3 +1,6 @@
const Sequelize = require('sequelize');
const logger = require('winston');
const Certificate = require('./certificate.js'); const Certificate = require('./certificate.js');
const Channel = require('./channel.js'); const Channel = require('./channel.js');
const Claim = require('./claim.js'); const Claim = require('./claim.js');
@ -6,10 +9,10 @@ const Request = require('./request.js');
const User = require('./user.js'); const User = require('./user.js');
const Blocked = require('./blocked.js'); const Blocked = require('./blocked.js');
const Sequelize = require('sequelize');
const logger = require('winston');
const {database, username, password} = require('@config/mysqlConfig'); const {database, username, password} = require('@config/mysqlConfig');
if (!database || !username || !password) {
logger.warn('missing database, user, or password from mysqlConfig');
}
// set sequelize options // set sequelize options
const sequelize = new Sequelize(database, username, password, { const sequelize = new Sequelize(database, username, password, {

View file

@ -1,7 +1,7 @@
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const {database, username, password} = require('@config/mysqlConfig');
const createDatabaseIfNotExists = () => { const createDatabaseIfNotExists = () => {
const {database, username, password} = require('@config/mysqlConfig');
const sequelize = new Sequelize('', username, password, { const sequelize = new Sequelize('', username, password, {
dialect : 'mysql', dialect : 'mysql',
logging : false, logging : false,

View file

@ -22,23 +22,17 @@ var _reactHelmet = _interopRequireDefault(require("react-helmet"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var siteConfig = require('@config/siteConfig');
module.exports = function (req, res) { 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 store = (0, _redux.createStore)(_reducers.default); // render component to a string
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 html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, { var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, {
store: store store: store
}, _react.default.createElement(_reactRouterDom.StaticRouter, { }, _react.default.createElement(_reactRouterDom.StaticRouter, {
location: req.url, location: req.url,
context: context 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 var helmet = _reactHelmet.default.renderStatic(); // check for a redirect

View file

@ -30,8 +30,6 @@ var _reactHelmet = _interopRequireDefault(require("react-helmet"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var siteConfig = require('@config/siteConfig');
var returnSagaWithParams = function returnSagaWithParams(saga, params) { var returnSagaWithParams = function returnSagaWithParams(saga, params) {
return ( return (
/*#__PURE__*/ /*#__PURE__*/
@ -54,16 +52,12 @@ var returnSagaWithParams = function returnSagaWithParams(saga, params) {
}; };
module.exports = function (req, res) { module.exports = function (req, res) {
var context = {}; // configure the reducers by passing initial state configs var context = {}; // create and apply middleware
var MyReducers = (0, _reducers.default)(siteConfig);
var MyApp = _app.default;
var MyGAListener = (0, _GAListener.default)(siteConfig); // create and apply middleware
var sagaMiddleware = (0, _reduxSaga.default)(); var sagaMiddleware = (0, _reduxSaga.default)();
var middleware = (0, _redux.applyMiddleware)(sagaMiddleware); // create a new Redux store instance 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); var action = _actions.default.onHandleShowPageUri(req.params);
@ -76,7 +70,7 @@ module.exports = function (req, res) {
}, _react.default.createElement(_reactRouterDom.StaticRouter, { }, _react.default.createElement(_reactRouterDom.StaticRouter, {
location: req.url, location: req.url,
context: context 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 var helmet = _reactHelmet.default.renderStatic(); // check for a redirect

View file

@ -9,26 +9,19 @@ import App from '@app';
import renderFullPage from '../renderFullPage.js'; import renderFullPage from '../renderFullPage.js';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
const siteConfig = require('@config/siteConfig');
module.exports = (req, res) => { module.exports = (req, res) => {
let context = {}; 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 // create a new Redux store instance
const store = createStore(MyReducers); const store = createStore(Reducers);
// render component to a string // render component to a string
const html = renderToString( const html = renderToString(
<Provider store={store}> <Provider store={store}>
<StaticRouter location={req.url} context={context}> <StaticRouter location={req.url} context={context}>
<MyGAListener> <GAListener>
<MyApp /> <App />
</MyGAListener> </GAListener>
</StaticRouter> </StaticRouter>
</Provider> </Provider>
); );

View file

@ -13,8 +13,6 @@ import Sagas from '@sagas';
import Actions from '@actions'; import Actions from '@actions';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
const siteConfig = require('@config/siteConfig');
const returnSagaWithParams = (saga, params) => { const returnSagaWithParams = (saga, params) => {
return function * () { return function * () {
yield call(saga, params); yield call(saga, params);
@ -24,17 +22,12 @@ const returnSagaWithParams = (saga, params) => {
module.exports = (req, res) => { module.exports = (req, res) => {
let context = {}; 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 // create and apply middleware
const sagaMiddleware = createSagaMiddleware(); const sagaMiddleware = createSagaMiddleware();
const middleware = applyMiddleware(sagaMiddleware); const middleware = applyMiddleware(sagaMiddleware);
// create a new Redux store instance // create a new Redux store instance
const store = createStore(MyReducers, middleware); const store = createStore(Reducers, middleware);
// create saga // create saga
const action = Actions.onHandleShowPageUri(req.params); const action = Actions.onHandleShowPageUri(req.params);
@ -49,9 +42,9 @@ module.exports = (req, res) => {
const html = renderToString( const html = renderToString(
<Provider store={store}> <Provider store={store}>
<StaticRouter location={req.url} context={context}> <StaticRouter location={req.url} context={context}>
<MyGAListener> <GAListener>
<MyApp /> <App />
</MyGAListener> </GAListener>
</StaticRouter> </StaticRouter>
</Provider> </Provider>
); );

View file

@ -1,17 +1,21 @@
const logger = require('winston'); const logger = require('winston');
const { logLevel } = require('@config/loggerConfig'); const config = require('@config/loggerConfig');
const { logLevel } = config;
function configureLogging () { function configureLogging () {
if (!logLevel) {
return logger.warn('No logLevel config received.');
}
logger.info('configuring winston logger...'); 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 // configure the winston logger
logger.configure({ logger.configure({
transports: [ transports: [
new (logger.transports.Console)({ new (logger.transports.Console)({
level : this.logLevel, level : logLevel || 'debug',
timestamp : false, timestamp : false,
colorize : true, colorize : true,
prettyPrint : true, prettyPrint : true,

View file

@ -1,19 +1,17 @@
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook; const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
const logger = require('winston'); const logger = require('winston');
const config = require('@config/loggerConfig'); const config = require('@config/slackConfig');
const {slackWebHook, slackErrorChannel, slackInfoChannel} = config;
function configureSlack () { function configureSlack () {
logger.info('configuring slack logger...');
if (!config) { if (!config) {
return logger.warn('No slack config found'); return logger.warn('No slack config found');
} }
const {slackWebHook, slackErrorChannel, slackInfoChannel} = config;
// update variables
logger.info('configuring slack logger...');
// update slack webhook settings // update slack webhook settings
if (!slackWebHook) { 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 // add a transport for errors to slack
if (slackErrorChannel) { if (slackErrorChannel) {
@ -25,6 +23,8 @@ function configureSlack () {
username : 'spee.ch', username : 'spee.ch',
iconEmoji : ':face_with_head_bandage:', iconEmoji : ':face_with_head_bandage:',
}); });
} else {
logger.warn('No slack error channel logging set up');
} }
// add a transport for info in slack // add a transport for info in slack
if (slackInfoChannel) { if (slackInfoChannel) {
@ -36,6 +36,8 @@ function configureSlack () {
username : 'spee.ch', username : 'spee.ch',
iconEmoji : ':nerd_face:', iconEmoji : ':nerd_face:',
}); });
} else {
logger.warn('No slack info channel logging set up');
} }
// send test messages // send test messages
logger.info('Slack logging is online.'); logger.info('Slack logging is online.');