From 18eaf81579f8078a60468ff02548b1315d64139e Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 2 May 2018 10:30:33 -0700 Subject: [PATCH 1/4] added separate views config file --- config/siteConfig.js | 10 +--------- config/slackConfig.js | 2 +- config/viewsConfig.js | 17 +++++++++++++++++ index.js | 8 ++------ 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 config/viewsConfig.js diff --git a/config/siteConfig.js b/config/siteConfig.js index af5e02f4..38a5bc67 100644 --- a/config/siteConfig.js +++ b/config/siteConfig.js @@ -10,9 +10,6 @@ function SiteConfig () { this.auth = { sessionKey: 'default', }; - this.customComponents = {}; - this.customContainers = {}; - this.customPages = {}; this.details = { description: 'Welcome to my decentralized image and video sharing site.', host : 'http://localhost:3000', @@ -29,22 +26,17 @@ function SiteConfig () { thumbnailChannelId : 'default', uploadDirectory : '/home/lbry/Uploads', }; - this.routes = {}; this.update = (config) => { if (!config) { return console.log('No site config received.'); } - const { analytics, assetDefaults, auth, customComponents, customContainers, customPages, details, publishing, routes } = config; + const { analytics, assetDefaults, auth, details, publishing } = config; console.log('Configuring site details...'); this.analytics = analytics; this.assetDefaults = assetDefaults; this.auth = auth; this.details = details; this.publishing = publishing; - this.customComponents = customComponents; - this.customContainers = customContainers; - this.customPages = customPages; - this.routes = routes; }; } diff --git a/config/slackConfig.js b/config/slackConfig.js index b9c8ab25..56008a27 100644 --- a/config/slackConfig.js +++ b/config/slackConfig.js @@ -28,7 +28,7 @@ function SlackConfig () { iconEmoji : ':face_with_head_bandage:', }); }; - if (slackInfoChannel) { + if (this.slackInfoChannel) { winston.add(winstonSlackWebHook, { name : 'slack-info-transport', level : 'info', diff --git a/config/viewsConfig.js b/config/viewsConfig.js new file mode 100644 index 00000000..11310efa --- /dev/null +++ b/config/viewsConfig.js @@ -0,0 +1,17 @@ +function ViewsConfig () { + this.components = {}; + this.containers = {}; + this.pages = {}; + this.update = (config) => { + if (!config) { + return console.log('No components config received.'); + } + const { components, containers, pages } = config; + console.log('Configuring custom components ...'); + this.components = components; + this.containers = containers; + this.pages = pages; + }; +} + +module.exports = new ViewsConfig(); diff --git a/index.js b/index.js index 0e2a6efc..60af5519 100644 --- a/index.js +++ b/index.js @@ -13,18 +13,14 @@ const loggerConfig = require('./config/loggerConfig.js'); const mysqlConfig = require('./config/mysqlConfig.js'); const siteConfig = require('./config/siteConfig.js'); const slackConfig = require('./config/slackConfig.js'); +const viewsConfig = require('./config/viewsConfig.js'); function Server () { this.configureLogger = loggerConfig.update; this.configureMysql = mysqlConfig.update; this.configureSite = siteConfig.update; this.configureSlack = slackConfig.update; - this.configureModels = () => { - logger.debug('here is where you could add/overwrite the default models') - }; - this.configureRoutes = () => { - logger.debug('here is where you could add/overwrite the default routes') - }; + this.configureViews = viewsConfig.update; this.createApp = () => { // create an Express application const app = express(); From 05822c393c00fb2c9ddc3d31d5e32e346c6a44dc Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 2 May 2018 11:52:19 -0700 Subject: [PATCH 2/4] rebuild jsx pages --- server/render/build/handlePageRender.js | 4 +++- server/render/build/handleShowRender.js | 4 +++- server/render/src/handlePageRender.jsx | 3 ++- server/render/src/handleShowRender.jsx | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/render/build/handlePageRender.js b/server/render/build/handlePageRender.js index e529fbf1..cbc803b9 100644 --- a/server/render/build/handlePageRender.js +++ b/server/render/build/handlePageRender.js @@ -27,11 +27,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de */ var siteConfig = require('../../../config/siteConfig.js'); +var viewsConfig = require('../../../config/viewsConfig.js'); + module.exports = function (req, res) { var context = {}; // customize the reducer by passing in intial state configs var MyReducers = (0, _spee.Reducers)(siteConfig); - var MyApp = (0, _spee.App)(siteConfig); + var MyApp = (0, _spee.App)(viewsConfig); var MyGAListener = (0, _spee.GAListener)(siteConfig); // create a new Redux store instance var store = (0, _redux.createStore)(MyReducers); // render component to a string diff --git a/server/render/build/handleShowRender.js b/server/render/build/handleShowRender.js index 04320311..cb7511a1 100644 --- a/server/render/build/handleShowRender.js +++ b/server/render/build/handleShowRender.js @@ -31,6 +31,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de */ var siteConfig = require('../../../config/siteConfig.js'); +var viewsConfig = require('../../../config/viewsConfig.js'); + var returnSagaWithParams = function returnSagaWithParams(saga, params) { return ( /*#__PURE__*/ @@ -56,7 +58,7 @@ module.exports = function (req, res) { var context = {}; // configure the reducers by passing initial state configs var MyReducers = (0, _spee.Reducers)(siteConfig); - var MyApp = (0, _spee.App)(siteConfig); + var MyApp = (0, _spee.App)(viewsConfig); var MyGAListener = (0, _spee.GAListener)(siteConfig); // create and apply middleware var sagaMiddleware = (0, _reduxSaga.default)(); diff --git a/server/render/src/handlePageRender.jsx b/server/render/src/handlePageRender.jsx index 8bc14d07..6479a808 100644 --- a/server/render/src/handlePageRender.jsx +++ b/server/render/src/handlePageRender.jsx @@ -15,13 +15,14 @@ import renderFullPage from '../renderFullPage.js'; import Helmet from 'react-helmet'; const siteConfig = require('../../../config/siteConfig.js'); +const viewsConfig = require('../../../config/viewsConfig.js'); module.exports = (req, res) => { let context = {}; // customize the reducer by passing in intial state configs const MyReducers = Reducers(siteConfig); - const MyApp = App(siteConfig); + const MyApp = App(viewsConfig); const MyGAListener = GAListener(siteConfig); // create a new Redux store instance diff --git a/server/render/src/handleShowRender.jsx b/server/render/src/handleShowRender.jsx index 9b5004f5..568ad877 100644 --- a/server/render/src/handleShowRender.jsx +++ b/server/render/src/handleShowRender.jsx @@ -17,6 +17,7 @@ import { Reducers, GAListener, App, Sagas, Actions } from 'spee.ch-components'; import Helmet from 'react-helmet'; const siteConfig = require('../../../config/siteConfig.js'); +const viewsConfig = require('../../../config/viewsConfig.js'); const returnSagaWithParams = (saga, params) => { return function * () { @@ -29,7 +30,7 @@ module.exports = (req, res) => { // configure the reducers by passing initial state configs const MyReducers = Reducers(siteConfig); - const MyApp = App(siteConfig); + const MyApp = App(viewsConfig); const MyGAListener = GAListener(siteConfig); // create and apply middleware From 8c50fc8b83d5fa7b48d45b7330cbc274b41edd72 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 2 May 2018 13:08:25 -0700 Subject: [PATCH 3/4] hard coded /public folder --- index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 60af5519..3b91ed8a 100644 --- a/index.js +++ b/index.js @@ -29,21 +29,18 @@ function Server () { app.enable('trust proxy'); /* add middleware */ + // set HTTP headers to protect against well-known web vulnerabilties app.use(helmet()); + // 'express.static' to serve static files from public directory - if (siteConfig.routes.publicFolder) { - // take in a different public folder, so it can serve it's own bundle if needed - const publicFolder = Path.resolve(process.cwd(), siteConfig.routes.publicFolder); - app.use(express.static(publicFolder)); - logger.info('serving static files from custom path:', publicFolder); - } else { - const publicPath = Path.resolve(process.cwd(), 'public'); - app.use(express.static(publicPath)); - logger.warn(`serving static files from default static path at ${publicPath}. Please specify a path in your config/siteConfig.js file`); - }; + 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/json app.use(bodyParser.json()); + // 'body parser' for parsing application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: true })); From c439e3d97189b7831ada9deb5c79e670b61aab0f Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 2 May 2018 18:16:23 -0700 Subject: [PATCH 4/4] added a debug for the publish params --- server/controllers/api/claim/publish/createBasicPublishParams.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/controllers/api/claim/publish/createBasicPublishParams.js b/server/controllers/api/claim/publish/createBasicPublishParams.js index a8d84404..7ede4ad7 100644 --- a/server/controllers/api/claim/publish/createBasicPublishParams.js +++ b/server/controllers/api/claim/publish/createBasicPublishParams.js @@ -34,6 +34,7 @@ const createBasicPublishParams = (filePath, name, title, description, license, n if (thumbnail) { publishParams['metadata']['thumbnail'] = thumbnail; } + logger.debug('publish params:', publishParams); return publishParams; };