Folder structure #398
16 changed files with 34 additions and 160 deletions
|
@ -1,19 +1,6 @@
|
|||
const logger = require('winston');
|
||||
|
||||
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
|
||||
logger.debug('serializing user');
|
||||
done(null, user);
|
||||
|
|
11
index.js
11
index.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,9 +1,9 @@
|
|||
import React from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import HomePage from 'components/HomePage';
|
||||
import AboutPage from 'components/AboutPage';
|
||||
import HomePage from 'pages/HomePage';
|
||||
import AboutPage from 'pages/AboutPage';
|
||||
import LoginPage from 'containers/LoginPage';
|
||||
import ShowPage from 'containers/ShowPage';
|
||||
import ShowPage from 'pages/ShowPage';
|
||||
import FourOhFourPage from 'containers/FourOhFourPage';
|
||||
|
||||
const App = () => {
|
||||
|
|
46
server.js
46
server.js
|
@ -5,35 +5,31 @@ const expressHandlebars = require('express-handlebars');
|
|||
const Handlebars = require('handlebars');
|
||||
const helmet = require('helmet');
|
||||
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 http = require('http');
|
||||
// logging dependencies
|
||||
const logger = require('winston');
|
||||
|
||||
function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
|
||||
this.start = () => {
|
||||
this.configureConfigFiles();
|
||||
this.configureLogging();
|
||||
this.configureApp();
|
||||
this.configureServer();
|
||||
this.startServer();
|
||||
function SpeechServer () {
|
||||
this.configureMysql = (mysqlConfig) => {
|
||||
require('./config/mysqlConfig.js').configure(mysqlConfig);
|
||||
};
|
||||
this.configureConfigFiles = () => {
|
||||
const mysqlAppConfig = require('./config/mysqlConfig.js');
|
||||
mysqlAppConfig.configure(mysqlConfig);
|
||||
const siteAppConfig = require('./config/siteConfig.js');
|
||||
siteAppConfig.configure(siteConfig);
|
||||
this.PORT = siteAppConfig.details.port;
|
||||
const slackAppConfig = require('./config/slackConfig.js');
|
||||
slackAppConfig.configure(slackConfig);
|
||||
this.configureSite = (siteConfig) => {
|
||||
require('./config/siteConfig.js').configure(siteConfig);
|
||||
this.sessionKey = siteConfig.auth.sessionKey;
|
||||
this.PORT = siteConfig.details.port;
|
||||
};
|
||||
this.configureSlack = (slackConfig) => {
|
||||
require('./config/slackConfig.js').configure(slackConfig);
|
||||
};
|
||||
this.configureLogging = () => {
|
||||
require('./helpers/configureLogger.js')(logger);
|
||||
require('./helpers/configureSlack.js')(logger);
|
||||
};
|
||||
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
|
||||
app.enable('trust proxy');
|
||||
|
@ -58,7 +54,7 @@ function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
|
|||
// initialize passport
|
||||
app.use(cookieSession({
|
||||
name : 'session',
|
||||
keys : [siteConfig.auth.sessionKey],
|
||||
keys : [this.sessionKey],
|
||||
maxAge: 24 * 60 * 60 * 1000, // i.e. 24 hours
|
||||
}));
|
||||
app.use(passport.initialize());
|
||||
|
@ -72,22 +68,24 @@ function SpeechServer ({ mysqlConfig, siteConfig, slackConfig }) {
|
|||
app.engine('handlebars', hbs.engine);
|
||||
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
|
||||
require('./routes/auth-routes.js')(app);
|
||||
require('./routes/api-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);
|
||||
|
||||
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.startServer = () => {
|
||||
this.blastoff = () => {
|
||||
const db = require('./models');
|
||||
// sync sequelize
|
||||
db.sequelize.sync()
|
||||
|
|
|
@ -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'],
|
||||
},
|
||||
};
|
|
@ -1,7 +0,0 @@
|
|||
const serverBaseConfig = require('./webpack.server.common.js');
|
||||
const clientBaseConfig = require('./webpack.client.common.js');
|
||||
|
||||
module.exports = [
|
||||
serverBaseConfig,
|
||||
clientBaseConfig,
|
||||
];
|
|
@ -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),
|
||||
];
|
|
@ -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),
|
||||
];
|
|
@ -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'],
|
||||
},
|
||||
};
|
Loading…
Add table
Reference in a new issue