forked from KevinSheedy/unpkg-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,16 @@ describe('A request to browse a directory', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('with invalid query params', () => { | ||
it('strips them from the query string', done => { | ||
request(server) | ||
.get('/browse/[email protected]/umd/?invalid') | ||
.end((err, res) => { | ||
expect(res.statusCode).toBe(302); | ||
expect(res.headers.location).toEqual('/browse/[email protected]/umd/'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,18 @@ describe('A request to browse a file', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('when the URL contains invalid query params', () => { | ||
it('strips them from the URL', done => { | ||
request(server) | ||
.get('/browse/[email protected]/react.production.min.js?invalid') | ||
.end((err, res) => { | ||
expect(res.statusCode).toBe(302); | ||
expect(res.headers.location).toBe( | ||
'/browse/[email protected]/react.production.min.js' | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Strips all query params from the URL to increase cache hit rates. | ||
*/ | ||
export default function noQuery() { | ||
return (req, res, next) => { | ||
const keys = Object.keys(req.query); | ||
|
||
if (keys.length) { | ||
return res.redirect(302, req.baseUrl + req.path); | ||
} | ||
|
||
next(); | ||
}; | ||
} |