Folder structure #398

Merged
bones7242 merged 76 commits from folder-structure into master 2018-03-20 00:01:08 +01:00
16 changed files with 34 additions and 160 deletions
Showing only changes of commit 4d9a255a3b - Show all commits

View file

@ -1,19 +1,6 @@
const logger = require('winston'); const logger = require('winston');
module.exports = { module.exports = {
populateLocalsDotUser (req, res, next) {
if (req.user) {
logger.debug('populating res.locals.user');
res.locals.user = {
id : req.user.id,
userName : req.user.userName,
channelName : req.user.channelName,
channelClaimId: req.user.channelClaimId,
shortChannelId: req.user.shortChannelId,
};
}
next();
},
serializeSpeechUser (user, done) { // returns user data to be serialized into session serializeSpeechUser (user, done) { // returns user data to be serialized into session
logger.debug('serializing user'); logger.debug('serializing user');
done(null, user); done(null, user);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Route, Switch } from 'react-router-dom'; import { Route, Switch } from 'react-router-dom';
import HomePage from 'components/HomePage'; import HomePage from 'pages/HomePage';
import AboutPage from 'components/AboutPage'; import AboutPage from 'pages/AboutPage';
import LoginPage from 'containers/LoginPage'; import LoginPage from 'containers/LoginPage';
import ShowPage from 'containers/ShowPage'; import ShowPage from 'pages/ShowPage';
import FourOhFourPage from 'containers/FourOhFourPage'; import FourOhFourPage from 'containers/FourOhFourPage';
const App = () => { const App = () => {

View file

@ -5,35 +5,31 @@ const expressHandlebars = require('express-handlebars');
const Handlebars = require('handlebars'); const Handlebars = require('handlebars');
const helmet = require('helmet'); const helmet = require('helmet');
const passport = require('passport'); const passport = require('passport');
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js'); const { serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
const cookieSession = require('cookie-session'); const cookieSession = require('cookie-session');
const http = require('http'); const http = require('http');
// logging dependencies // logging dependencies
const logger = require('winston'); const logger = require('winston');
function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) { function SpeechServer () {
this.start = () => { this.configureMysql = (mysqlConfig) => {
this.configureConfigFiles(); require('./config/mysqlConfig.js').configure(mysqlConfig);
this.configureLogging();
this.configureApp();
this.configureServer();
this.startServer();
}; };
this.configureConfigFiles = () => { this.configureSite = (siteConfig) => {
const mysqlAppConfig = require('./config/mysqlConfig.js'); require('./config/siteConfig.js').configure(siteConfig);
mysqlAppConfig.configure(mysqlConfig); this.sessionKey = siteConfig.auth.sessionKey;
const siteAppConfig = require('./config/siteConfig.js'); this.PORT = siteConfig.details.port;
siteAppConfig.configure(siteConfig); };
this.PORT = siteAppConfig.details.port; this.configureSlack = (slackConfig) => {
const slackAppConfig = require('./config/slackConfig.js'); require('./config/slackConfig.js').configure(slackConfig);
slackAppConfig.configure(slackConfig);
}; };
this.configureLogging = () => { this.configureLogging = () => {
require('./helpers/configureLogger.js')(logger); require('./helpers/configureLogger.js')(logger);
require('./helpers/configureSlack.js')(logger); require('./helpers/configureSlack.js')(logger);
}; };
this.configureApp = () => { this.configureApp = () => {
const app = express(); // create an Express application // create an Express application
const app = express();
// trust the proxy to get ip address for us // trust the proxy to get ip address for us
app.enable('trust proxy'); app.enable('trust proxy');
@ -58,7 +54,7 @@ function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
// initialize passport // initialize passport
app.use(cookieSession({ app.use(cookieSession({
name : 'session', name : 'session',
keys : [siteConfig.auth.sessionKey], keys : [this.sessionKey],
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
})); }));
app.use(passport.initialize()); app.use(passport.initialize());
@ -72,22 +68,24 @@ function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
app.engine('handlebars', hbs.engine); app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars'); app.set('view engine', 'handlebars');
// middleware to pass user info back to client (for handlebars access), if user is logged in
app.use(populateLocalsDotUser); // note: I don't think I need this any more?
// set the routes on the app // set the routes on the app
require('./routes/auth-routes.js')(app); require('./routes/auth-routes.js')(app);
require('./routes/api-routes.js')(app); require('./routes/api-routes.js')(app);
require('./routes/page-routes.js')(app); require('./routes/page-routes.js')(app);
require('./routes/serve-routes.js')(app); require('./routes/asset-routes.js')(app);
require('./routes/fallback-routes.js')(app); require('./routes/fallback-routes.js')(app);
this.app = app; this.app = app;
}; };
this.configureServer = () => { this.initialize = (pages, models, routes) => {
this.configureLogging();
this.configureApp();
this.updatePages(pages);
this.updateModels(models);
this.updateRoutes(routes);
this.server = http.Server(this.app); this.server = http.Server(this.app);
}; };
this.startServer = () => { this.blastoff = () => {
const db = require('./models'); const db = require('./models');
// sync sequelize // sync sequelize
db.sequelize.sync() db.sequelize.sync()

View file

@ -1,32 +0,0 @@
const Path = require('path');
const REACT_ROOT = Path.resolve(__dirname, 'react/');
module.exports = {
target: 'web',
entry : ['babel-polyfill', 'whatwg-fetch', './react/client.js'],
output: {
path : Path.join(__dirname, 'public/bundle/'),
publicPath: 'public/bundle/',
filename : 'bundle.js',
},
module: {
loaders: [
{
test : /.jsx?$/,
loader : 'babel-loader',
exclude: /node_modules/,
query : {
presets: ['es2015', 'react', 'stage-2'],
},
},
],
},
resolve: {
modules: [
REACT_ROOT,
'node_modules',
__dirname,
],
extensions: ['.js', '.jsx', '.scss'],
},
};

View file

@ -1,7 +0,0 @@
const serverBaseConfig = require('./webpack.server.common.js');
const clientBaseConfig = require('./webpack.client.common.js');
module.exports = [
serverBaseConfig,
clientBaseConfig,
];

View file

@ -1,13 +0,0 @@
const serverBaseConfig = require('./webpack.server.common.js');
const clientBaseConfig = require('./webpack.client.common.js');
const merge = require('webpack-merge');
const devBuildConfig = {
watch : true,
devtool: 'inline-source-map',
};
module.exports = [
merge(serverBaseConfig, devBuildConfig),
merge(clientBaseConfig, devBuildConfig),
];

View file

@ -1,22 +0,0 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const serverBaseConfig = require('./webpack.server.common.js');
const clientBaseConfig = require('./webpack.client.common.js');
const productionBuildConfig = {
devtool: 'source-map',
plugins: [
new UglifyJSPlugin({
sourceMap: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
};
module.exports = [
merge(serverBaseConfig, productionBuildConfig),
merge(clientBaseConfig, productionBuildConfig),
];

View file

@ -1,43 +0,0 @@
const Path = require('path');
const nodeExternals = require('webpack-node-externals');
const REACT_ROOT = Path.resolve(__dirname, 'react/');
module.exports = {
target: 'node',
node : {
__dirname: false,
},
externals: [nodeExternals()],
entry : ['babel-polyfill', 'whatwg-fetch', './server.js'],
output : {
path : Path.join(__dirname, '/'),
publicPath : '/',
filename : 'index.js',
library : '',
libraryTarget: 'commonjs-module',
},
module: {
rules: [
{
test : /.jsx?$/,
exclude: /node_modules/,
loader : 'babel-loader',
options: {
presets: ['es2015', 'react', 'stage-2'],
},
},
{
test : /.css$/,
loader: 'css-loader',
},
],
},
resolve: {
modules: [
REACT_ROOT,
'node_modules',
__dirname,
],
extensions: ['.js', '.json', '.jsx', '.css'],
},
};