From a15d2eade7b0af71177b3afe80c0e8c2a6ca83e9 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:15:08 -0700 Subject: [PATCH 1/4] add ejs templating and serve coral-admin from /admin --- app.js | 7 +++++++ client/coral-admin/webpack.config.dev.js | 10 ---------- client/coral-admin/webpack.config.js | 9 --------- package.json | 5 +++-- client/coral-admin/index.ejs => views/admin.ejs | 0 5 files changed, 10 insertions(+), 21 deletions(-) rename client/coral-admin/index.ejs => views/admin.ejs (100%) diff --git a/app.js b/app.js index 838819e35..5d91243e8 100644 --- a/app.js +++ b/app.js @@ -3,11 +3,14 @@ const bodyParser = require('body-parser'); const morgan = require('morgan'); const path = require('path'); +const adminConfig = require('./client/coral-admin/config'); const app = express(); // Middleware declarations. app.use(morgan('dev')); app.use(bodyParser.json()); +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'ejs'); // API Routes. app.use('/api/v1', require('./routes/api')); @@ -15,4 +18,8 @@ app.use('/api/v1', require('./routes/api')); // Static Routes. app.use('/client/', express.static(path.join(__dirname, 'dist'))); +app.get('/admin/*', (req, res) => { + res.render('admin', {basePath: '/client/coral-admin'}); +}); + module.exports = app; diff --git a/client/coral-admin/webpack.config.dev.js b/client/coral-admin/webpack.config.dev.js index bd5913b5a..1eba29d66 100644 --- a/client/coral-admin/webpack.config.dev.js +++ b/client/coral-admin/webpack.config.dev.js @@ -1,16 +1,6 @@ - const path = require('path') -const fs = require('fs') const autoprefixer = require('autoprefixer') const precss = require('precss') -const config = require('./config.json') - -// doing a string replace here because I spent a day trying to do it the "webpack" way -// ond nothing works. just trying to replace a string in an index.html file is -// apparently something no one has ever done in the js community. -let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() -templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = { entry: { diff --git a/client/coral-admin/webpack.config.js b/client/coral-admin/webpack.config.js index 2c81bf4fc..10768b6e5 100644 --- a/client/coral-admin/webpack.config.js +++ b/client/coral-admin/webpack.config.js @@ -1,17 +1,8 @@ const path = require('path') -const fs = require('fs') const devConfig = require('./webpack.config.dev') const autoprefixer = require('autoprefixer') const precss = require('precss') const Copy = require('copy-webpack-plugin') -const config = require('./config.json') - -// doing a string replace here because I spent a day trying to do it the "webpack" way -// ond nothing works. just trying to replace a string in an index.html file is -// apparently something no one has ever done in the js community. -let templateString = fs.readFileSync(path.join(__dirname, 'index.ejs')).toString() -templateString = templateString.replace('<%= basePath %>', config.basePath) -fs.writeFileSync(path.join(__dirname, 'public/index.html'), templateString) module.exports = Object.assign({}, devConfig, { module: { diff --git a/package.json b/package.json index 0c7aab592..bbd097221 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,11 @@ "dependencies": { "body-parser": "^1.15.2", "debug": "^2.2.0", + "ejs": "^2.5.2", "express": "^4.14.0", "mongoose": "^4.6.5", - "uuid": "^2.0.3", - "morgan": "^1.7.0" + "morgan": "^1.7.0", + "uuid": "^2.0.3" }, "devDependencies": { "babel-core": "6.14.0", diff --git a/client/coral-admin/index.ejs b/views/admin.ejs similarity index 100% rename from client/coral-admin/index.ejs rename to views/admin.ejs From b6355b06db8f95c1359c980acc3324b2ffed5e02 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:24:46 -0700 Subject: [PATCH 2/4] remove unused var --- app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app.js b/app.js index 5d91243e8..76dba1c1a 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,6 @@ const bodyParser = require('body-parser'); const morgan = require('morgan'); const path = require('path'); -const adminConfig = require('./client/coral-admin/config'); const app = express(); // Middleware declarations. From 6f6da144015a956e360125aa5dd034c61da2ca80 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 11:27:47 -0700 Subject: [PATCH 3/4] fix build script a bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbd097221..ee92db73f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "app.js", "scripts": { "start": "./bin/www", - "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && cd client/coral-admin && npm run build", + "build": "./node_modules/webpack/bin/webpack.js --config ./client/coral-embed-stream/webpack.config.js && cd client/coral-admin && npm install && npm run build", "lint": "eslint .", "pretest": "npm install", "test": "mocha tests --recursive", From 80f1f70a2a76f3662b3623df79412390b873ed20 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 8 Nov 2016 12:03:49 -0700 Subject: [PATCH 4/4] hardcode routes in react app --- client/coral-admin/.gitignore | 1 - client/coral-admin/config.json | 5 +++++ client/coral-admin/src/components/App.js | 9 ++++----- client/coral-admin/src/components/Header.js | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 client/coral-admin/config.json diff --git a/client/coral-admin/.gitignore b/client/coral-admin/.gitignore index c9c7cb580..707c890e5 100644 --- a/client/coral-admin/.gitignore +++ b/client/coral-admin/.gitignore @@ -3,5 +3,4 @@ public/bundle.js public/embed/comment-stream .DS_Store npm-debug.log -config.json yarn.lock diff --git a/client/coral-admin/config.json b/client/coral-admin/config.json new file mode 100644 index 000000000..c8f318cfc --- /dev/null +++ b/client/coral-admin/config.json @@ -0,0 +1,5 @@ +{ + "basePath": "admin", + "talkHost": "http://localhost:16180", + "xeniaHost": "http://localhost:16180" +} diff --git a/client/coral-admin/src/components/App.js b/client/coral-admin/src/components/App.js index 4b7c01e84..81eea850f 100644 --- a/client/coral-admin/src/components/App.js +++ b/client/coral-admin/src/components/App.js @@ -8,17 +8,16 @@ import store from 'services/store' import CommentStream from 'containers/CommentStream' import EmbedLink from 'components/EmbedLink' import Configure from 'containers/Configure' -import config from 'services/config' export default class App extends React.Component { render (props) { return ( - - - - + + + + ) diff --git a/client/coral-admin/src/components/Header.js b/client/coral-admin/src/components/Header.js index 0e52686d8..ea268108e 100644 --- a/client/coral-admin/src/components/Header.js +++ b/client/coral-admin/src/components/Header.js @@ -9,14 +9,14 @@ export default (props) => (
- Moderate - Configure + Moderate + Configure
- Moderate - Configure + Moderate + Configure {props.children}