Created
August 11, 2023 22:56
-
-
Save MRezaSafari/22d2b467522845fbbbdfaed1a9303fce to your computer and use it in GitHub Desktop.
fetch interceptor
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
export const interceptor = async () => { | |
const { fetch: originalFetch } = window; | |
window.fetch = async (...args) => { | |
let [resource, config] = args; | |
const URLcutOff = "https://myapi.com"; | |
const trailing = resource.slice(URLcutOff.length); | |
console.log(trailing); | |
if (trailing.startsWith("/posts")) { | |
resource = `https://myapi.com`; | |
} | |
const response = await originalFetch(resource, config); | |
return response; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment