diff --git a/pages/api/[...id].ts b/pages/api/[...id].ts index b408e5d..27aff90 100644 --- a/pages/api/[...id].ts +++ b/pages/api/[...id].ts @@ -1,36 +1,41 @@ -import type { NextApiRequest, NextApiResponse } from 'next' -import axios from 'axios'; -import * as LanyardTypes from '../../src/LanyardTypes'; -import renderCard from '../../src/renderCard'; +import type { NextApiRequest, NextApiResponse } from "next"; +import axios from "axios"; +import renderCard from "../../src/renderCard"; type Data = { - id?: string | string[] - error?: any; -} + id?: string | string[]; + error?: any; +}; type Parameters = { - animated?: string; -} + animated?: string; +}; export default async function handler( - req: NextApiRequest, - res: NextApiResponse + req: NextApiRequest, + res: NextApiResponse, ) { + let params: Parameters = req.query, + userid = req.query.id[0], + lanyardData: any; - let params: Parameters = req.query, - userid = req.query.id[0], - lanyardData: any; + res.setHeader("Content-Type", "image/svg+xml; charset=utf-8"); + res.setHeader( + "content-security-policy", + "default-src 'none'; img-src * data:; style-src 'unsafe-inline'", + ); - res.setHeader("Content-Type", "image/svg+xml; charset=utf-8"); - res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'"); + try { + lanyardData = await axios.get( + `https://api.lanyard.rest/v1/users/${userid}`, + ); + } catch (e) { + console.log(e); + res.send({ + error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.`, + }); + } - try { - lanyardData = await axios.get(`https://api.lanyard.rest/v1/users/${userid}`); - } catch (e) { - console.log(e) - res.send({ error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.` }) - } - - let svg = await renderCard(lanyardData.data, params); - res.status(200).send(svg as any); -} \ No newline at end of file + let svg = await renderCard(lanyardData.data, params); + res.status(200).send(svg as any); +}