Fix configs loading #470
15 changed files with 426 additions and 428 deletions
|
@ -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)({
|
||||
var _default = (0, _redux.combineReducers)({
|
||||
channel: _channel.default,
|
||||
channelCreate: _channelCreate.default,
|
||||
publish: (0, _publish.default)(siteConfig),
|
||||
publish: _publish.default,
|
||||
show: _show.default,
|
||||
site: (0, _site.default)(siteConfig)
|
||||
});
|
||||
};
|
||||
site: _site.default
|
||||
});
|
||||
|
||||
var _default = customizedReducers;
|
||||
exports.default = _default;
|
|
@ -9,28 +9,31 @@ 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;
|
||||
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
|
||||
} // create initial state
|
||||
|
||||
|
||||
var initialState = {
|
||||
var initialState = {
|
||||
disabled: disabledConfig,
|
||||
disabledMessage: disabledMessageConfig,
|
||||
publishInChannel: false,
|
||||
|
@ -56,8 +59,9 @@ var customizedPublishReducer = function customizedPublishReducer(siteConfig) {
|
|||
thumbnail: null,
|
||||
thumbnailChannel: thumbnailChannel,
|
||||
thumbnailChannelId: thumbnailChannelId
|
||||
};
|
||||
return function () {
|
||||
};
|
||||
|
||||
var _default = function _default() {
|
||||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
||||
var action = arguments.length > 1 ? arguments[1] : undefined;
|
||||
|
||||
|
@ -114,8 +118,6 @@ var customizedPublishReducer = function customizedPublishReducer(siteConfig) {
|
|||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _default = customizedPublishReducer;
|
||||
exports.default = _default;
|
|
@ -5,15 +5,26 @@ 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,
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
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.details,
|
||||
_siteConfig$details = _siteConfig.default.details,
|
||||
description = _siteConfig$details.description,
|
||||
host = _siteConfig$details.host,
|
||||
title = _siteConfig$details.title,
|
||||
|
@ -27,19 +38,9 @@ var customizedSiteReducer = function customizedSiteReducer(siteConfig) {
|
|||
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 _default = function _default() {
|
||||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
||||
var action = arguments.length > 1 ? arguments[1] : undefined;
|
||||
|
||||
|
@ -47,8 +48,6 @@ var customizedSiteReducer = function customizedSiteReducer(siteConfig) {
|
|||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _default = customizedSiteReducer;
|
||||
exports.default = _default;
|
|
@ -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({
|
||||
export default combineReducers({
|
||||
channel : ChannelReducer,
|
||||
channelCreate: ChannelCreateReducer,
|
||||
publish : PublishReducer(siteConfig),
|
||||
publish : PublishReducer,
|
||||
show : ShowReducer,
|
||||
site : SiteReducer(siteConfig),
|
||||
})
|
||||
};
|
||||
|
||||
export default customizedReducers;
|
||||
site : SiteReducer,
|
||||
});
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
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) {
|
||||
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 = {
|
||||
}
|
||||
|
||||
// create initial state
|
||||
const initialState = {
|
||||
disabled : disabledConfig,
|
||||
disabledMessage : disabledMessageConfig,
|
||||
publishInChannel : false,
|
||||
|
@ -42,8 +44,9 @@ const customizedPublishReducer = (siteConfig) => {
|
|||
thumbnail: null,
|
||||
thumbnailChannel,
|
||||
thumbnailChannelId,
|
||||
};
|
||||
return (state = initialState, action) => {
|
||||
};
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case actions.FILE_SELECTED:
|
||||
return Object.assign({}, initialState, { // note: clears to initial state
|
||||
|
@ -90,7 +93,4 @@ const customizedPublishReducer = (siteConfig) => {
|
|||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default customizedPublishReducer;
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
const customizedSiteReducer = (siteConfig) => {
|
||||
let initialState = {};
|
||||
if (siteConfig) {
|
||||
import siteConfig from '@config/siteConfig';
|
||||
|
||||
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,
|
||||
|
@ -26,23 +36,11 @@ const customizedSiteReducer = (siteConfig) => {
|
|||
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) => {
|
||||
}
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default customizedSiteReducer;
|
||||
|
|
70
index.js
70
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,34 +15,36 @@ 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 = () => {
|
||||
function Server () {
|
||||
this.initialize = () => {
|
||||
// configure logging
|
||||
configureLogging();
|
||||
|
||||
// configure slack logging
|
||||
configureSlack();
|
||||
|
||||
};
|
||||
this.createApp = () => {
|
||||
/* create app */
|
||||
const app = express();
|
||||
|
||||
|
@ -83,20 +92,32 @@ const startServer = () => {
|
|||
require('./server/routes/assets')(app);
|
||||
require('./server/routes/fallback')(app);
|
||||
|
||||
this.app = app;
|
||||
};
|
||||
this.createServer = () => {
|
||||
/* create server */
|
||||
const server = http.Server(app);
|
||||
|
||||
/* start the server */
|
||||
createDatabaseIfNotExists()
|
||||
this.server = http.Server(this.app);
|
||||
};
|
||||
this.syncDatabase = () => {
|
||||
return createDatabaseIfNotExists()
|
||||
.then(() => {
|
||||
return getWalletBalance();
|
||||
})
|
||||
.then(balance => {
|
||||
logger.info('starting LBC balance:', balance);
|
||||
db.sequelize.sync();
|
||||
server.listen(PORT, () => {
|
||||
})
|
||||
};
|
||||
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') {
|
||||
|
@ -106,6 +127,7 @@ const startServer = () => {
|
|||
}
|
||||
logger.error(error);
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = startServer;
|
||||
module.exports = Server;
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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(
|
||||
<Provider store={store}>
|
||||
<StaticRouter location={req.url} context={context}>
|
||||
<MyGAListener>
|
||||
<MyApp />
|
||||
</MyGAListener>
|
||||
<GAListener>
|
||||
<App />
|
||||
</GAListener>
|
||||
</StaticRouter>
|
||||
</Provider>
|
||||
);
|
||||
|
|
|
@ -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(
|
||||
<Provider store={store}>
|
||||
<StaticRouter location={req.url} context={context}>
|
||||
<MyGAListener>
|
||||
<MyApp />
|
||||
</MyGAListener>
|
||||
<GAListener>
|
||||
<App />
|
||||
</GAListener>
|
||||
</StaticRouter>
|
||||
</Provider>
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.');
|
||||
|
|
Loading…
Reference in a new issue