Skip to content

Commit

Permalink
[self] tested well. Comments are added
Browse files Browse the repository at this point in the history
  • Loading branch information
Huxpro committed Nov 3, 2016
1 parent 8989cf9 commit 27fdf28
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ const getFixedUrl = (req) => {
const isNavigationReq = (req) => (req.mode === 'navigate' || (req.method === 'GET' && req.headers.get('accept').includes('text/html')))

// Redirect in SW manually fixed github pages 404s on repo?blah
// if An url is navigation and isnt end with '/' (indicate github would 404s on it )
// it should be a dir request and need to fixed
// P.S. An url.pathname has no '.' cant indicate it's file (e.g. http://test.com/api/version/1.2/)
// If It's a navigation req and it's url.pathname isn't end with '/' (indicate github might well 404 on it )
// it should be a dir/repo request and need to be fixed (a.k.a be redirected)
// P.S. An url.pathname has no '.' can not indicate it's file (e.g. http://test.com/api/version/1.2/)
// https://twitter.com/Huxpro/status/793519812127227905
const shouldRedirect = (req) => (isNavigationReq(req) && new URL(req.url).pathname.substr(-1) !== "/")

// The Util Function to get redirect URL
// `${url}/` would mis-add "/" in the end of query, so we use URL object.
// P.P.S. Always trust url.pathname instead of the whole url string.
const getRedirectUrl = (req) => {
url = new URL(req.url)
url.pathname += "/"
Expand Down

0 comments on commit 27fdf28

Please sign in to comment.