import { GetServerSideProps, InferGetServerSidePropsType } from 'next'; import Meta from 'src/components/meta/Meta'; import Layout from 'src/components/layout'; import ErrorInfo from 'src/components/error/ErrorInfo'; import Media from 'src/components/media/Media'; import { Basic, Credits, DidYouKnow, Info, Bio, KnownFor } from 'src/components/name'; import Name from 'src/interfaces/shared/name'; import { AppError } from 'src/interfaces/shared/error'; import name from 'src/utils/fetchers/name'; import getOrSetApiCache from 'src/utils/getOrSetApiCache'; import { getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers'; import { nameKey } from 'src/utils/constants/keys'; import styles from 'src/styles/modules/pages/name/name.module.scss'; type Props = InferGetServerSidePropsType; const NameInfo = ({ data, error, originalPath }: Props) => { if (error) return ; return ( <>
); }; type Data = ({ data: Name; error: null } | { error: AppError; data: null }) & { originalPath: string; }; type Params = { nameId: string }; export const getServerSideProps: GetServerSideProps = async ctx => { const nameId = ctx.params!.nameId; const originalPath = ctx.resolvedUrl; try { const data = await getOrSetApiCache(nameKey(nameId), name, nameId); return { props: { data, error: null, originalPath } }; } catch (error) { const err = getErrorProperties(error); ctx.res.statusCode = err.statusCode; ctx.res.statusMessage = err.message; return { props: { error: { message: err.message, statusCode: err.statusCode, stack: err.format() }, data: null, originalPath, }, }; } }; export default NameInfo;