Skip to content

Instantly share code, notes, and snippets.

@blift
Created March 10, 2022 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blift/026495a8685225016376a4d0ade2d2e0 to your computer and use it in GitHub Desktop.
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
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