mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-26 13:41:32 +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";
|
import { ServerStyleSheet } from "styled-components";
|
||||||
|
|
||||||
export default class MyDocument extends Document {
|
export default class MyDocument extends Document {
|
||||||
static async getInitialProps(ctx) {
|
static async getInitialProps(ctx: any) {
|
||||||
const sheet = new ServerStyleSheet(),
|
const sheet = new ServerStyleSheet(),
|
||||||
originalRenderPage = ctx.renderPage;
|
originalRenderPage = ctx.renderPage;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ctx.renderPage = () =>
|
ctx.renderPage = () =>
|
||||||
originalRenderPage({
|
originalRenderPage({
|
||||||
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
|
enhanceApp: (App: any) => (props: any) => sheet.collectStyles(<App {...props} />),
|
||||||
});
|
});
|
||||||
|
|
||||||
const initialProps = await Document.getInitialProps(ctx);
|
const initialProps = await Document.getInitialProps(ctx);
|
||||||
@@ -18,23 +18,23 @@ type Parameters = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
||||||
let axiosRes;
|
let getUser;
|
||||||
const params: Parameters = req.query,
|
const params: Parameters = req.query,
|
||||||
userid = req.query.id[0];
|
userId = req.query.id[0];
|
||||||
|
|
||||||
if (!isSnowflake(userid))
|
if (!isSnowflake(userId))
|
||||||
return res.send({
|
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 {
|
try {
|
||||||
axiosRes = await axios.get(`https://api.lanyard.rest/v1/users/${userid}`);
|
getUser = await axios(`https://api.lanyard.rest/v1/users/${userId}`);
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
console.log(err);
|
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.`,
|
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-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-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);
|
res.status(200).send(svg as any);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import styled, { createGlobalStyle, GlobalStyleComponent } from "styled-components";
|
import styled, { createGlobalStyle } from "styled-components";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"next-env.d.ts",
|
"next-env.d.ts",
|
||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"**/*.tsx",
|
"**/*.tsx",
|
||||||
"pages/_document.js"
|
"pages/_document.tsx"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
|
|||||||
Reference in New Issue
Block a user