Skip to content

Commit

Permalink
refactor: utilize route.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Dec 28, 2019
1 parent eb1c4f0 commit fa37ce3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/middlewares/pre_compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = function(app) {

app.use(root, (req, res, next) => {
const { headers, method } = req;
const routeList = route.list();
const url = decodeURIComponent(req.url);
const acceptEncoding = headers['accept-encoding'] || '';
const reqUrl = url.endsWith('/') ? url.concat('index.html') : url;
Expand All @@ -21,10 +20,10 @@ module.exports = function(app) {

res.setHeader('Content-Type', contentType + '; charset=utf-8');

if (acceptEncoding.includes('br') && (routeList.includes(url.slice(1) + '.br') || url.endsWith('/'))) {
if (acceptEncoding.includes('br') && (route.get(url.slice(1) + '.br') || url.endsWith('/'))) {
req.url = encodeURI(reqUrl + '.br');
res.setHeader('Content-Encoding', 'br');
} else if (acceptEncoding.includes('gzip') && (routeList.includes(url.slice(1) + '.gz') || url.endsWith('/'))) {
} else if (acceptEncoding.includes('gzip') && (route.get(url.slice(1) + '.gz') || url.endsWith('/'))) {
req.url = encodeURI(reqUrl + '.gz');
res.setHeader('Content-Encoding', 'gzip');
}
Expand Down

0 comments on commit fa37ce3

Please sign in to comment.