Skip to content

Commit

Permalink
fix: /docs/network-edge/pops redirect loop
Browse files Browse the repository at this point in the history
Before this, going to https://ngrok.com/docs/network-edge/pops/ would
redirect loop.

The reason for this is twofold:

1. The match should have been exact, since the redirect was a prefix of
   itself
2. The redirect check at the bottom checked href
   ('https://ngrok.com/docs/....') against a path ('/docs/') to see if
   they were the same, and so they never were.

This updates that check as well.
  • Loading branch information
euank committed Sep 17, 2024
1 parent f043b39 commit 4fbef15
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions static/scripts/fix-redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const toReplace = (to) => (path, from) => path.replace(from, to) // a
// List of redirects
// String values are treated as exacts by default.
// Exact matches should be listed first as redirects are stacked
//
//
// To change behavior you can use the following method structures:
// [0 - from]: (path) => [matchStr, boolean (true for match, false for do not match)]
// [1 - to]: (path, from) => string (returned value becomes the new path)
const redirects = [
// exact matches
[ fromExact(`/docs/network-edge/pops`), `/docs/network-edge/pops/` ],

[ fromIncludes(`/docs/1`), `/docs/` ],
[ fromIncludes(`/docs/2`), `/docs/` ],
[ fromIncludes(`/docs/ngrok-link`), `/docs/network-edge/` ],
Expand All @@ -21,7 +24,6 @@ const redirects = [
[ fromIncludes(`/docs/platform/events`), `/docs/events/` ],
[ fromIncludes(`/docs/events/filtering`), `/docs/events/#filters` ],
[ fromIncludes(`/docs/http-header-templates/`), `/docs/network-edge/http-header-templates/` ],
[ fromIncludes(`/docs/network-edge/pops`), `/docs/network-edge/pops/` ],
[ fromIncludes(`/docs/platform/pops`), `/docs/network-edge/pops/` ],
[ fromIncludes(`/docs/best-practices/security-dev-productivity/`), `/docs/guides/security-dev-productivity/` ],
[ fromIncludes(`/docs/platform/ip-policies/`), `/docs/network-edge/ip-policies/` ],
Expand Down Expand Up @@ -147,6 +149,8 @@ for (const redirect of redirects) {
}

// redirect when the path has changed
if (newPath != currentPath) {
if (newPath != currentPath && newPath != window.location.pathname) {
window.location.href = newPath
}
} else {
console.error(`ignoring redirect from ${window.location.href} to ${newPath}; looks loopy`)
}

0 comments on commit 4fbef15

Please sign in to comment.