mirror of
https://github.com/wassname/talk.git
synced 2026-08-04 13:23:35 +08:00
added middleware wrap
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user