-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix cors issue in dev environment when accessing api.coingecko.com
- Loading branch information
Showing
2 changed files
with
27 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export async function GET(_: Request, { params: { symbol } }: { params: { symbol: string } }) { | ||
let apiUrl = ""; | ||
if (symbol === "ETH") { | ||
apiUrl = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"; | ||
} else if (symbol === "STRK") { | ||
apiUrl = "https://api.coingecko.com/api/v3/simple/price?ids=starknet&vs_currencies=usd"; | ||
} else { | ||
return Response.json({ | ||
ethereum: { usd: 0 }, | ||
starknet: { usd: 0 } | ||
}); | ||
} | ||
try { | ||
const response = await fetch(apiUrl); | ||
if (!response.ok) { | ||
throw new Error(`coingecko response status: ${response.status}`); | ||
} | ||
const json = await response.json(); | ||
return Response.json(json); | ||
} catch (e) { | ||
return Response.json({ | ||
ethereum: { usd: 0 }, | ||
starknet: { usd: 0 } | ||
}); | ||
} | ||
} |
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