icns-frontend/pages/api/icns-verification.ts

33 lines
1015 B
TypeScript
Raw Normal View History

import { withIronSessionApiRoute } from "iron-session/next";
import type { NextApiRequest, NextApiResponse } from "next";
import { ironOptions } from "../../iron.config";
2022-12-05 15:22:45 +00:00
import { IcnsVerificationResponse } from "../../types/api-response";
import { request } from "../../utils/url";
export default withIronSessionApiRoute(async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
try {
if (!process.env.ICNS_VERIFIER_URI) {
console.log(".env is not set");
return res.status(500).json({ error: "Internal server error" });
}
2022-12-05 15:22:45 +00:00
const icnsVerificationInfo = await request<IcnsVerificationResponse>(
process.env.ICNS_VERIFIER_URI,
{
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(req.body),
},
);
res.status(200).json(icnsVerificationInfo);
} catch (error) {
console.error(error);
res.status(500).json({ error: "Internal server error" });
}
},
ironOptions);