added middleware wrap

This commit is contained in:
Wyatt Johnson
2017-05-18 11:27:28 -06:00
parent 12713dae86
commit 4dc83aaf63
2 changed files with 36 additions and 16 deletions
+23 -8
View File
@@ -32,17 +32,32 @@ app.use(helmet({
frameguard: false
}));
app.use(bodyParser.json());
app.get('*.js', (req, res, next) => {
const accept = accepts(req);
if (accept.encoding(['gzip']) === 'gzip') {
req.url = `${req.url}.gz`;
res.set('Content-Encoding', 'gzip');
}
next();
});
//==============================================================================
// STATIC FILES
//==============================================================================
// If the application is in production mode, then add gzip rewriting for the
// content.
if (process.env.NODE_ENV === 'production') {
app.get('*.js', (req, res, next) => {
const accept = accepts(req);
if (accept.encoding(['gzip']) === 'gzip') {
req.url = `${req.url}.gz`;
res.set('Content-Encoding', 'gzip');
}
next();
});
}
app.use('/client', express.static(path.join(__dirname, 'dist')));
app.use('/public', express.static(path.join(__dirname, 'public')));
//==============================================================================
// VIEW CONFIGURATION
//==============================================================================
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
+13 -8
View File
@@ -37,7 +37,7 @@ const buildEmbeds = [
'stream'
];
module.exports = {
const config = {
devtool: 'cheap-module-source-map',
entry: Object.assign({}, {
'embed': [
@@ -142,13 +142,6 @@ module.exports = {
}),
new webpack.EnvironmentPlugin({
'TALK_PLUGINS_JSON': '{}'
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js)$/,
threshold: 10240,
minRatio: 0.8
})
],
resolveLoader: {
@@ -168,3 +161,15 @@ module.exports = {
]
}
};
if (process.env.NODE_ENV === 'production') {
config.plugins.push(new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js)$/,
threshold: 10240,
minRatio: 0.8
}));
}
module.exports = config;