Created
March 10, 2022 17:39
-
-
Save blift/026495a8685225016376a4d0ade2d2e0 to your computer and use it in GitHub Desktop.
Function for bud (sage 10) replacing proxy urls in theme in dev mode to localhost urls
This file contains hidden or 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
async function UrlChanger() { | |
const { headers } = await fetch(window.location.origin, { | |
method: 'GET', | |
}) | |
const origin = { | |
proxy: headers.get('x-bud-proxy-origin'), | |
dev: headers.get('x-bud-dev-origin'), | |
} | |
const aHref = document.getElementsByTagName('a') | |
let listOfLinks = Array.prototype.slice.call(aHref) | |
if (origin.dev) { | |
listOfLinks.forEach(function (part) { | |
let proxyHref = part.getAttribute('href') | |
if (proxyHref.includes(origin.proxy)) { | |
part.setAttribute('href', proxyHref.replace(origin.proxy, origin.dev)) | |
} | |
}) | |
} | |
} | |
export default UrlChanger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment