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:
19
server.js
19
server.js
@@ -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')());
|
||||
|
||||
Reference in New Issue
Block a user