-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6856c4f
commit 3be7b75
Showing
3 changed files
with
21 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
export function proxyify(url: string) { | ||
return `https://corsproxy.io/?${encodeURIComponent(url)}`; | ||
export function proxyify(url: string): string { | ||
// Only use the CORS proxy if the endpoint is defined. | ||
if (import.meta.env.VITE_CORS_PROXY_ENDPOINT) { | ||
return `${import.meta.env.VITE_CORS_PROXY_ENDPOINT}${encodeURIComponent(url)}`; | ||
} | ||
return `${url}`; | ||
} | ||
|
||
export function fetchWithProxy(url: string) { | ||
return fetch(`https://corsproxy.io/?${encodeURIComponent(url)}`); | ||
export async function fetchWithProxy(url: string): Promise<Response> { | ||
return fetch(proxyify(url)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
/** | ||
* Used to configure the CORS proxy endpoint, this is set in the github action during the build/deployment. | ||
*/ | ||
readonly VITE_CORS_PROXY_ENDPOINT: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |