mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-25 04:17:18 +00:00
Merge pull request #17 from Looskie/main
This commit is contained in:
@@ -2,14 +2,14 @@ import Document from "next/document";
|
||||
import { ServerStyleSheet } from "styled-components";
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
static async getInitialProps(ctx) {
|
||||
static async getInitialProps(ctx: any) {
|
||||
const sheet = new ServerStyleSheet(),
|
||||
originalRenderPage = ctx.renderPage;
|
||||
|
||||
try {
|
||||
ctx.renderPage = () =>
|
||||
originalRenderPage({
|
||||
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
|
||||
enhanceApp: (App: any) => (props: any) => sheet.collectStyles(<App {...props} />),
|
||||
});
|
||||
|
||||
const initialProps = await Document.getInitialProps(ctx);
|
||||
@@ -18,23 +18,23 @@ type Parameters = {
|
||||
};
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
||||
let axiosRes;
|
||||
let getUser;
|
||||
const params: Parameters = req.query,
|
||||
userid = req.query.id[0];
|
||||
userId = req.query.id[0];
|
||||
|
||||
if (!isSnowflake(userid))
|
||||
if (!isSnowflake(userId))
|
||||
return res.send({
|
||||
error: `Specify a valid Discord user ID! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.`,
|
||||
error: `That is not a valid snowflake ID!`,
|
||||
});
|
||||
|
||||
try {
|
||||
axiosRes = await axios.get(`https://api.lanyard.rest/v1/users/${userid}`);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
getUser = await axios(`https://api.lanyard.rest/v1/users/${userId}`);
|
||||
} catch (error) {
|
||||
if (error.response.status === 404) return res.status(404).send({ error: "Invalid user!" });
|
||||
|
||||
if (err.response.status === 404) return res.send({ error: "Invalid user!" });
|
||||
console.log(error); // Only console log the error if its not a 404
|
||||
|
||||
return res.send({
|
||||
return res.status(400).send({
|
||||
error: `Something went wrong! If everything looks correct and this still occurs, please contact @cnraddd on Twitter.`,
|
||||
});
|
||||
}
|
||||
@@ -42,6 +42,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
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'");
|
||||
|
||||
let svg = await renderCard(axiosRes.data, params);
|
||||
const svg = await renderCard(getUser.data, params);
|
||||
res.status(200).send(svg as any);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Head from "next/head";
|
||||
import styled, { createGlobalStyle, GlobalStyleComponent } from "styled-components";
|
||||
import styled, { createGlobalStyle } from "styled-components";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function Home() {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"pages/_document.js"
|
||||
"pages/_document.tsx"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
||||
Reference in New Issue
Block a user