ens-proxy/pages/api/address.ts

20 lines
566 B
TypeScript
Raw Normal View History

2022-08-18 15:51:38 +02:00
import { NextApiRequest, NextApiResponse } from 'next'
import { getEns } from './_utils'
export default async function getEnsAddress(
request: NextApiRequest,
response: NextApiResponse
) {
try {
const ensName = request.query.name
const ens = await getEns()
const address = await ens.name(ensName).getAddress()
2022-08-18 16:23:04 +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-18 15:51:38 +02:00
response.status(200).send(address)
} catch (error) {
response.status(500).send(`${error}`)
}
}