0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-01 04:29:29 +00:00

Serve compressed static files if available

This commit is contained in:
Trevor Buckner
2020-11-11 21:19:49 -05:00
parent 3b52888877
commit 600ca90fc0
2 changed files with 27 additions and 1 deletions

View File

@@ -1,11 +1,30 @@
const _ = require('lodash');
const jwt = require('jwt-simple');
const fs = require('fs-extra');
const express = require('express');
const app = express();
const homebrewApi = require('./server/homebrew.api.js');
const GoogleActions = require('./server/googleActions.js');
// Serve brotli-compressed static files if available
app.get('*.js', 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('*.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.use(express.static(`${__dirname}/build`));
app.use(require('body-parser').json({ limit: '25mb' }));
app.use(require('cookie-parser')());