-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from EveripediaNetwork/implement-api-caching
Refactoring and Improving Price related API Route
- Loading branch information
Showing
17 changed files
with
275 additions
and
106 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
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
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,29 +1,47 @@ | ||
import config from '@/config' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { ResponseData } from '@/types/TreasuryTokenType' | ||
import { setCacheHeaders } from '@/utils/cache' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData>, | ||
) { | ||
const { walletAddress } = req.query | ||
if (!walletAddress) { | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
if (req.method !== 'GET') { | ||
return res | ||
.status(400) | ||
.json({ status: false, message: 'Wallet address are needed' }) | ||
.status(405) | ||
.json({ status: false, message: 'Method not allowed' }) | ||
} | ||
try { | ||
const { walletAddress } = req.query | ||
if (!walletAddress) { | ||
return res | ||
.status(400) | ||
.json({ status: false, message: 'Wallet address are needed' }) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/all_token_list?id=${walletAddress}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
|
||
setCacheHeaders(res) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'token details successfully fetched', | ||
}) | ||
} catch (error) { | ||
console.error('Fetch token error:', error) | ||
|
||
return res.status(500).json({ | ||
status: false, | ||
message: | ||
error instanceof Error | ||
? error.message | ||
: 'Failed to fetch token details', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/all_token_list?id=${walletAddress}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'token details successfully fetched', | ||
}) | ||
} |
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
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,30 +1,47 @@ | ||
import config from '@/config' | ||
import { ResponseData } from '@/types/TreasuryTokenType' | ||
import { setCacheHeaders } from '@/utils/cache' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<ResponseData>, | ||
) { | ||
const { protocolId, id } = req.query | ||
if (!protocolId || !id) { | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(400).json({ | ||
if (req.method !== 'GET') { | ||
return res | ||
.status(405) | ||
.json({ status: false, message: 'Method not allowed' }) | ||
} | ||
try { | ||
const { protocolId, id } = req.query | ||
if (!protocolId || !id) { | ||
return res.status(400).json({ | ||
status: false, | ||
message: 'protocol id and wallet address are needed', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/protocol?protocol_id=${protocolId}&id=${id}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
setCacheHeaders(res) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'protocol details successfully fetched', | ||
}) | ||
} catch (error) { | ||
console.error('Fetch protocol details error:', error) | ||
|
||
return res.status(500).json({ | ||
status: false, | ||
message: 'protocol id and wallet address are needed', | ||
message: | ||
error instanceof Error | ||
? error.message | ||
: 'Failed to fetch protocol details', | ||
}) | ||
} | ||
const url = `https://pro-openapi.debank.com/v1/user/protocol?protocol_id=${protocolId}&id=${id}&is_all=true` | ||
const result = await fetch(url, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accesskey: `${config.debankApiKey}`, | ||
}, | ||
}) | ||
res.setHeader('Cache-Control', `s-maxage=${config.CACHE_DURATION_SECONDS}`) | ||
return res.status(200).json({ | ||
response: await result.json(), | ||
status: true, | ||
message: 'protocol details successfully fetched', | ||
}) | ||
} |
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
Oops, something went wrong.