-
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.
Uma nova rota para criptomoedas está sendo testada e implementada, pode ter bugs e problemas de formatação.
- Loading branch information
1 parent
6a4cef3
commit cd9ee92
Showing
2 changed files
with
58 additions
and
0 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,27 @@ | ||
import axios from 'axios'; | ||
|
||
export default async function handler(request, response) { | ||
try { | ||
const apiKey = process.env.APIKEYCRYPTO; | ||
|
||
const response = await axios.get('https://api.coingecko.com/api/v3/coins/markets', { | ||
params: { | ||
vs_currency: 'brl', | ||
order: 'market_cap_desc', | ||
per_page: 15000, | ||
page: 1, | ||
sparkline: false, | ||
x_cg_demo_api_key: apiKey | ||
}, | ||
}); | ||
|
||
response.setHeader('Vercel-CDN-Cache-Control', 'max-age=86400'); | ||
response.setHeader('CDN-Cache-Control', 'max-age=86400'); | ||
response.setHeader('Cache-Control', 'max-age=86400'); | ||
|
||
const data = response.data; | ||
response.status(200).json(data); | ||
} catch (error) { | ||
response.status(500).json({ error: error.message }); | ||
} | ||
} |
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,31 @@ | ||
import axios from 'axios'; | ||
|
||
export default async function handler(request, response) { | ||
try { | ||
let { coin } = request.query; | ||
const apiKey = process.env.APIKEYCRYPTO; | ||
|
||
if (typeof coin !== 'string') { | ||
throw new Error('Coin parameter must be a string'); | ||
} | ||
|
||
coin = coin.toLowerCase(); | ||
|
||
const response = await axios.get(`https://api.coingecko.com/api/v3/simple/price`, { | ||
params: { | ||
ids: `${coin}`, | ||
vs_currencies: "brl", | ||
x_cg_demo_api_key: apiKey | ||
}, | ||
}); | ||
|
||
response.setHeader('Vercel-CDN-Cache-Control', 'max-age=86400'); | ||
response.setHeader('CDN-Cache-Control', 'max-age=86400'); | ||
response.setHeader('Cache-Control', 'max-age=86400'); | ||
|
||
const data = response.data; | ||
response.status(200).json(data); | ||
} catch (error) { | ||
response.status(500).json({ error: error.message }); | ||
} | ||
} |