Skip to content

Commit fa37ce3

Browse files
committed
refactor: utilize route.get()
1 parent eb1c4f0 commit fa37ce3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/middlewares/pre_compressed.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = function(app) {
1010

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

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

24-
if (acceptEncoding.includes('br') && (routeList.includes(url.slice(1) + '.br') || url.endsWith('/'))) {
23+
if (acceptEncoding.includes('br') && (route.get(url.slice(1) + '.br') || url.endsWith('/'))) {
2524
req.url = encodeURI(reqUrl + '.br');
2625
res.setHeader('Content-Encoding', 'br');
27-
} else if (acceptEncoding.includes('gzip') && (routeList.includes(url.slice(1) + '.gz') || url.endsWith('/'))) {
26+
} else if (acceptEncoding.includes('gzip') && (route.get(url.slice(1) + '.gz') || url.endsWith('/'))) {
2827
req.url = encodeURI(reqUrl + '.gz');
2928
res.setHeader('Content-Encoding', 'gzip');
3029
}

0 commit comments

Comments
 (0)