2022-08-22 14:42:40 +02:00
|
|
|
import type { VercelRequest, VercelResponse } from '@vercel/node'
|
2022-08-22 14:09:50 +02:00
|
|
|
import { getProvider } from './_utils'
|
2022-08-18 15:51:38 +02:00
|
|
|
|
|
|
|
export default async function getEnsAddress(
|
2022-08-22 14:42:40 +02:00
|
|
|
request: VercelRequest,
|
|
|
|
response: VercelResponse
|
2022-08-18 15:51:38 +02:00
|
|
|
) {
|
|
|
|
try {
|
|
|
|
const ensName = request.query.name
|
2022-08-22 14:09:50 +02:00
|
|
|
const provider = await getProvider()
|
|
|
|
const address = await provider.resolveName(ensName)
|
2022-08-24 15:49:17 +02:00
|
|
|
if (!address) throw `No address found for ${ensName}`
|
2022-08-18 15:51:38 +02:00
|
|
|
|
2022-08-22 12:57:25 +02:00
|
|
|
response.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
2022-08-24 15:49:17 +02:00
|
|
|
response.status(200).send({ address })
|
2022-08-18 15:51:38 +02:00
|
|
|
} catch (error) {
|
2022-08-24 15:49:17 +02:00
|
|
|
response.send({ error })
|
2022-08-18 15:51:38 +02:00
|
|
|
}
|
|
|
|
}
|