mirror of
				https://github.com/skidoodle/erettsegi-browser.git
				synced 2025-02-15 05:39:15 +01:00 
			
		
		
		
	| @@ -1,12 +1,33 @@ | |||||||
| import { Footer } from '@/components/Footer' | import { Footer } from '@/components/Footer' | ||||||
| import { Button } from '@nextui-org/button' | import { Button } from '@nextui-org/button' | ||||||
| import Link from 'next/link' |  | ||||||
| import type { GetServerSideProps, GetServerSidePropsContext } from 'next' | import type { GetServerSideProps, GetServerSidePropsContext } from 'next' | ||||||
|  |  | ||||||
| interface ErrorProps { | interface ErrorProps { | ||||||
|   statusCode: number |   statusCode: number | ||||||
| } | } | ||||||
|  |  | ||||||
|  | const NotFound: React.FC = () => ( | ||||||
|  |   <> | ||||||
|  |     <p className='mt-2'>Az keresett oldal nem található.</p> | ||||||
|  |     <p className='mt-8 text-center'> | ||||||
|  |       <Button color='primary' onPress={() => (window.location.href = '/')}> | ||||||
|  |         Vissza | ||||||
|  |       </Button> | ||||||
|  |     </p> | ||||||
|  |   </> | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | const Unexpected: React.FC = () => ( | ||||||
|  |   <> | ||||||
|  |     <p className='mt-2'>Váratlan hiba történt.</p> | ||||||
|  |     <p className='mt-8 text-center'> | ||||||
|  |       <Button color='primary' onPress={() => (window.location.href = '/')}> | ||||||
|  |         Vissza | ||||||
|  |       </Button> | ||||||
|  |     </p> | ||||||
|  |   </> | ||||||
|  | ) | ||||||
|  |  | ||||||
| const ErrorPage: React.FC<ErrorProps> = ({ statusCode }) => { | const ErrorPage: React.FC<ErrorProps> = ({ statusCode }) => { | ||||||
|   return ( |   return ( | ||||||
|     <> |     <> | ||||||
| @@ -19,25 +40,14 @@ const ErrorPage: React.FC<ErrorProps> = ({ statusCode }) => { | |||||||
|             <div className='flex flex-col items-center justify-center'> |             <div className='flex flex-col items-center justify-center'> | ||||||
|               <div className='mt-5 mb-3'> |               <div className='mt-5 mb-3'> | ||||||
|                 <div className='text-2xl font-semibold text-gray-600'> |                 <div className='text-2xl font-semibold text-gray-600'> | ||||||
|                   {statusCode == 404 ? ( |                   {(() => { | ||||||
|                     <> |                     switch (statusCode) { | ||||||
|                       <p className='mt-2'>Az keresett oldal nem található.</p> |                       case 404: | ||||||
|                       <p className='mt-8 text-center'> |                         return <NotFound /> | ||||||
|                         <Button color='primary'> |                       default: | ||||||
|                           <Link href='/'>{'Vissza'}</Link> |                         return <Unexpected /> | ||||||
|                         </Button> |                     } | ||||||
|                       </p> |                   })()} | ||||||
|                     </> |  | ||||||
|                   ) : ( |  | ||||||
|                     <> |  | ||||||
|                       <p className='mt-2'>Váratlan hiba történt.</p> |  | ||||||
|                       <p className='mt-8 text-center'> |  | ||||||
|                         <Button color='primary'> |  | ||||||
|                           <Link href='/'>{'Vissza'}</Link> |  | ||||||
|                         </Button> |  | ||||||
|                       </p> |  | ||||||
|                     </> |  | ||||||
|                   )} |  | ||||||
|                 </div> |                 </div> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ export default async function handler( | |||||||
| ) { | ) { | ||||||
|   const { link } = req.query as { link: string } |   const { link } = req.query as { link: string } | ||||||
|   let missingParam: string | null = null |   let missingParam: string | null = null | ||||||
|  |  | ||||||
|   if (!link) { |   if (!link) { | ||||||
|     missingParam = 'link' |     missingParam = 'link' | ||||||
|   } |   } | ||||||
| @@ -15,20 +16,26 @@ export default async function handler( | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   const domain = link.split('/')[2] |   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' }) |     return res.status(400).json({ error: 'Érvénytelen link' }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   try { |   try { | ||||||
|     res.setHeader('Cache-Control', 's-maxage=31536000') |  | ||||||
|     const { protocol, host } = new URL(link) |     const { protocol, host } = new URL(link) | ||||||
|     if (protocol && host) { |     if (!protocol || !host) { | ||||||
|       const response = await fetch(link, { method: 'HEAD' }) |  | ||||||
|       const status = response.status |  | ||||||
|       res.status(200).json({ status }) |  | ||||||
|     } else { |  | ||||||
|       return res.status(400).json({ error: 'Érvénytelen link' }) |       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) { |   } catch (error) { | ||||||
|     res.status(500).json({ error: 'Internal Server Error' }) |     res.status(500).json({ error: 'Internal Server Error' }) | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user