diff --git a/src/pages/_error.tsx b/src/pages/_error.tsx index 9d964d5..67b2174 100644 --- a/src/pages/_error.tsx +++ b/src/pages/_error.tsx @@ -1,12 +1,33 @@ import { Footer } from '@/components/Footer' import { Button } from '@nextui-org/button' -import Link from 'next/link' import type { GetServerSideProps, GetServerSidePropsContext } from 'next' interface ErrorProps { statusCode: number } +const NotFound: React.FC = () => ( + <> +

Az keresett oldal nem található.

+

+ +

+ +) + +const Unexpected: React.FC = () => ( + <> +

Váratlan hiba történt.

+

+ +

+ +) + const ErrorPage: React.FC = ({ statusCode }) => { return ( <> @@ -19,25 +40,14 @@ const ErrorPage: React.FC = ({ statusCode }) => {
- {statusCode == 404 ? ( - <> -

Az keresett oldal nem található.

-

- -

- - ) : ( - <> -

Váratlan hiba történt.

-

- -

- - )} + {(() => { + switch (statusCode) { + case 404: + return + default: + return + } + })()}
diff --git a/src/pages/api/validate.ts b/src/pages/api/validate.ts index 1963150..004d0ac 100644 --- a/src/pages/api/validate.ts +++ b/src/pages/api/validate.ts @@ -6,6 +6,7 @@ export default async function handler( ) { const { link } = req.query as { link: string } let missingParam: string | null = null + if (!link) { missingParam = 'link' } @@ -15,20 +16,26 @@ export default async function handler( } const domain = link.split('/')[2] - if (domain !== 'erettsegi.albert.lol') { + if (domain !== 'localhost:3000' && domain !== 'erettsegi.albert.lol') { return res.status(400).json({ error: 'Érvénytelen link' }) } try { - res.setHeader('Cache-Control', 's-maxage=31536000') const { protocol, host } = new URL(link) - if (protocol && host) { - const response = await fetch(link, { method: 'HEAD' }) - const status = response.status - res.status(200).json({ status }) - } else { + if (!protocol || !host) { return res.status(400).json({ error: 'Érvénytelen link' }) } + + const response = await fetch(link, { method: 'OPTIONS' }) + + if (!response.ok) { + return res + .status(400) + .json({ error: 'Invalid host or network unreachable' }) + } + + const status = response.status + res.status(200).json({ status }) } catch (error) { res.status(500).json({ error: 'Internal Server Error' }) }