0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Use a library instead. Checks that the browser is compatible first.

This commit is contained in:
Trevor Buckner
2020-11-11 22:01:42 -05:00
parent 759d986188
commit 4182c79354
3 changed files with 23 additions and 9 deletions

8
package-lock.json generated
View File

@@ -3413,6 +3413,14 @@
}
}
},
"express-static-gzip": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/express-static-gzip/-/express-static-gzip-2.1.0.tgz",
"integrity": "sha512-XGozfjgsfVKBc8lQmPco9zd1+sK9Wy1ZPEAYtH8E34FbBr5BFp2HV+V1PpmIYHaWg8+ecLl/JnQkREbtPSJyxQ==",
"requires": {
"serve-static": "^1.14.1"
}
},
"extend": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",

View File

@@ -49,6 +49,7 @@
"cookie-parser": "^1.4.5",
"create-react-class": "^15.6.3",
"express": "^4.17.1",
"express-static-gzip": "2.1.0",
"fs-extra": "9.0.1",
"googleapis": "59.0.0",
"jwt-simple": "^0.5.6",

View File

@@ -1,6 +1,7 @@
const _ = require('lodash');
const jwt = require('jwt-simple');
const fs = require('fs-extra');
const expressStaticGzip = require('express-static-gzip');
const express = require('express');
const app = express();
@@ -8,16 +9,20 @@ const homebrewApi = require('./server/homebrew.api.js');
const GoogleActions = require('./server/googleActions.js');
// Serve brotli-compressed static files if available
app.get(['*.js', '*.css'], function(req, res, next) {
if(fs.existsSync(`build${req.url}.br`)){
req.url = `${req.url}.br`;
res.set('Content-Encoding', 'br');
res.set('Content-Type', 'text/javascript');
}
next();
});
// app.get(['*.js', '*.css'], function(req, res, next) {
// if(fs.existsSync(`build${req.url}.br`)){
// req.url = `${req.url}.br`;
// res.set('Content-Encoding', 'br');
// }
// next();
// });
app.use(express.static(`${__dirname}/build`));
app.use('/', expressStaticGzip(`${__dirname}/build`, {
enableBrotli: true,
orderPreference: ['br']
}));
//app.use(express.static(`${__dirname}/build`));
app.use(require('body-parser').json({ limit: '25mb' }));
app.use(require('cookie-parser')());
app.use(require('./server/forcessl.mw.js'));