From c698ae78a7aae2ea980a7b00df98435cb5e41dcb Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Thu, 10 Nov 2016 13:02:52 -0700 Subject: [PATCH 1/6] initialize settings in an init file before app accepts requests --- bin/www | 34 +++++++++++++++++++--------------- init.js | 6 ++++++ models/setting.js | 8 ++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 init.js diff --git a/bin/www b/bin/www index af91c2c40..6ebfc6944 100755 --- a/bin/www +++ b/bin/www @@ -13,27 +13,31 @@ process.env.DEBUG = process.env.TALK_DEBUG; const app = require('../app'); const debug = require('debug')('talk:server'); const http = require('http'); +const initPromise = require('../init'); +let server; -/** - * Get port from environment and store in Express. - */ +initPromise.then(() => { + /** + * Get port from environment and store in Express. + */ -const port = normalizePort(process.env.TALK_PORT || '3000'); -app.set('port', port); + const port = normalizePort(process.env.TALK_PORT || '3000'); + app.set('port', port); -/** - * Create HTTP server. - */ + /** + * Create HTTP server. + */ -const server = http.createServer(app); + server = http.createServer(app); -/** - * Listen on provided port, on all network interfaces. - */ + /** + * Listen on provided port, on all network interfaces. + */ -server.listen(port); -server.on('error', onError); -server.on('listening', onListening); + server.listen(port); + server.on('error', onError); + server.on('listening', onListening); +}); /** * Normalize a port into a number, string, or false. diff --git a/init.js b/init.js new file mode 100644 index 000000000..9c3c2bda5 --- /dev/null +++ b/init.js @@ -0,0 +1,6 @@ +const Setting = require('./models/setting'); + +const defaults = {id: '1', moderation: 'pre'}; +module.exports = Setting.init(defaults); + +// presumably this file will grow, which is why I've broken it out. diff --git a/models/setting.js b/models/setting.js index 15c457307..a9b60abb8 100644 --- a/models/setting.js +++ b/models/setting.js @@ -11,6 +11,14 @@ const SettingSchema = new Schema({ } }); +/** + * this is run once when the app starts to ensure settings are populated + * @return {Promise} null initialize the global settings object + */ +SettingSchema.statics.init = function (defaults) { + return this.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); +}; + /** * gets the entire settings record and sends it back * @return {Promise} settings the whole settings record From 677faebf7685551a456d4203e0bc003be0f958f1 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Thu, 10 Nov 2016 13:09:23 -0700 Subject: [PATCH 2/6] adhere to new linting rules --- bin/www | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/www b/bin/www index 6ebfc6944..639852a93 100755 --- a/bin/www +++ b/bin/www @@ -16,7 +16,8 @@ const http = require('http'); const initPromise = require('../init'); let server; -initPromise.then(() => { +initPromise +.then(() => { /** * Get port from environment and store in Express. */ From 7a8cb90ebd7ab741b0a9e5a5794087c1d4f03a62 Mon Sep 17 00:00:00 2001 From: David Erwin Date: Thu, 10 Nov 2016 15:28:14 -0500 Subject: [PATCH 3/6] Fix port scope bug --- bin/www | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/bin/www b/bin/www index 639852a93..792a6b98a 100755 --- a/bin/www +++ b/bin/www @@ -14,31 +14,32 @@ const app = require('../app'); const debug = require('debug')('talk:server'); const http = require('http'); const initPromise = require('../init'); +const port = normalizePort(process.env.TALK_PORT || '3000'); + let server; initPromise -.then(() => { - /** - * Get port from environment and store in Express. - */ + .then(() => { + /** + * Get port from environment and store in Express. + */ - const port = normalizePort(process.env.TALK_PORT || '3000'); - app.set('port', port); + app.set('port', port); - /** - * Create HTTP server. - */ + /** + * Create HTTP server. + */ - server = http.createServer(app); + server = http.createServer(app); - /** - * Listen on provided port, on all network interfaces. - */ + /** + * Listen on provided port, on all network interfaces. + */ - server.listen(port); - server.on('error', onError); - server.on('listening', onListening); -}); + server.listen(port); + server.on('error', onError); + server.on('listening', onListening); + }); /** * Normalize a port into a number, string, or false. From 6f7fe6ace7c6373c0f22d246c17adbd4bf18816f Mon Sep 17 00:00:00 2001 From: David Erwin Date: Thu, 10 Nov 2016 17:12:32 -0500 Subject: [PATCH 4/6] Add embedding routes and homepage --- app.js | 3 +- client/coral-admin/src/AppRouter.js | 2 - .../coral-admin/src/components/EmbedLink.css | 13 ------- .../coral-admin/src/components/EmbedLink.js | 37 ------------------- .../coral-admin/src/containers/Configure.js | 3 +- routes/index.js | 22 +++++++++++ views/embed/stream.ejs | 13 +++++++ views/home.ejs | 16 ++++++++ 8 files changed, 53 insertions(+), 56 deletions(-) delete mode 100644 client/coral-admin/src/components/EmbedLink.css delete mode 100644 client/coral-admin/src/components/EmbedLink.js create mode 100644 routes/index.js create mode 100644 views/embed/stream.ejs create mode 100644 views/home.ejs diff --git a/app.js b/app.js index 04e4222cd..22f343221 100644 --- a/app.js +++ b/app.js @@ -17,9 +17,8 @@ app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // Routes. -app.use('/api/v1', require('./routes/api')); app.use('/client', express.static(path.join(__dirname, 'dist'))); -app.use('/admin', require('./routes/admin')); +app.use('/', require('./routes')); //============================================================================== // ERROR HANDLING diff --git a/client/coral-admin/src/AppRouter.js b/client/coral-admin/src/AppRouter.js index d00caa6c5..d1b25d0f1 100644 --- a/client/coral-admin/src/AppRouter.js +++ b/client/coral-admin/src/AppRouter.js @@ -3,7 +3,6 @@ import {Router, Route, IndexRoute, browserHistory} from 'react-router'; import ModerationQueue from 'containers/ModerationQueue'; import CommentStream from 'containers/CommentStream'; -import EmbedLink from 'components/EmbedLink'; import Configure from 'containers/Configure'; import CommunityContainer from 'containers/CommunityContainer'; import LayoutContainer from 'containers/LayoutContainer'; @@ -12,7 +11,6 @@ const routes = ( - diff --git a/client/coral-admin/src/components/EmbedLink.css b/client/coral-admin/src/components/EmbedLink.css deleted file mode 100644 index 15583414a..000000000 --- a/client/coral-admin/src/components/EmbedLink.css +++ /dev/null @@ -1,13 +0,0 @@ -#embedLink { - width:400px; - margin-left: auto; - margin-right: auto; -} - -.embedTextarea { - width: 100%; -} - -.copyButton { - margin-top: 20px; -} diff --git a/client/coral-admin/src/components/EmbedLink.js b/client/coral-admin/src/components/EmbedLink.js deleted file mode 100644 index 41cbdf170..000000000 --- a/client/coral-admin/src/components/EmbedLink.js +++ /dev/null @@ -1,37 +0,0 @@ -import React from 'react'; -import styles from './EmbedLink.css'; -import I18n from 'coral-framework/i18n/i18n'; -import translations from '../translations'; -import {Button} from 'react-mdl'; - -const embedText = -`
`; - -const copyToClipBoard = () => { - const copyTextarea = document.querySelector(`.${ styles.embedTextarea}`); - copyTextarea.select(); - - try { - document.execCommand('copy'); - } catch (err) { - console.error('Unable to copy'); - } -}; - -const EmbedLink = () =>
-

Embed Comment Stream

-