Add missing static files middleware

This commit is contained in:
LordMathis 2018-06-24 23:05:34 +02:00
parent d1e23af74b
commit 1e23e7df65
1 changed files with 28 additions and 0 deletions

28
src/utils/staticFiles.js Normal file
View File

@ -0,0 +1,28 @@
const staticFiles = require('express').Router();
const path = require('path');
staticFiles.get('/bundle.js', (req, res) => {
if (req.acceptsEncodings('gzip')) {
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/javascript');
res.sendFile(path.join(process.cwd(), '/public/static/bundle.js.gz'));
} else {
res.sendFile(path.join(process.cwd(), '/public/static/bundle.js'));
}
});
staticFiles.get('/bundle.css', (req, res) => {
if (req.acceptsEncodings('gzip')) {
res.set('Content-Encoding', 'gzip');
res.set('Content-Type', 'text/css');
res.sendFile(path.join(process.cwd(), '/public/static/bundle.css.gz'));
} else {
res.sendFile(path.join(process.cwd(), '/public/static/bundle.css'));
}
});
staticFiles.get('*.jpg', (req, res) => {
res.sendFile(path.join(process.cwd(), '/public/static', req.url))
});
module.exports = staticFiles;