Skip to content

Commit

Permalink
feat: add leather request header
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Nov 25, 2024
1 parent 1df32aa commit 04ea43b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BlockchainApiClientProvider } from '@components/blockchain-api-client-p
import { Navigate } from '@components/navigate';
import { StackingClientProvider } from '@components/stacking-client-provider/stacking-client-provider';
import { NetworkModeUrlMap } from '@constants/network';
import { setupLeatherFetchInterceptor } from '@utils/fetch-interceptor';
import { loadFonts } from '@utils/load-fonts';

import { AuthGuard } from './components/auth-guard';
Expand Down Expand Up @@ -46,6 +47,8 @@ const queryClient = new QueryClient({
},
});

setupLeatherFetchInterceptor();

function Root() {
useEffect(() => void loadFonts(), []);

Expand Down
20 changes: 20 additions & 0 deletions src/utils/fetch-interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function setupLeatherFetchInterceptor() {
const originalFetch = window.fetch;

window.fetch = async function (input: RequestInfo | URL, init?: RequestInit) {
const url = input instanceof URL ? input.toString() : input.toString();

if (url.includes('hiro.so')) {
const modifiedInit = {
...init,
headers: {
...init?.headers,
'x-hiro-product': 'Leather',
},
};
return await originalFetch(input, modifiedInit);
}

return await originalFetch(input, init);
};
}

0 comments on commit 04ea43b

Please sign in to comment.