mirror of
https://github.com/skidoodle/erettsegi-browser.git
synced 2025-02-15 05:39:15 +01:00
30 lines
844 B
TypeScript
30 lines
844 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
const { link } = req.query as { link: string }
|
|
let MissingParam: string | null = null
|
|
if (!link) {
|
|
MissingParam = 'link'
|
|
}
|
|
|
|
if (MissingParam) {
|
|
return res.status(400).json({ error: `Hiányzó paraméter: ${MissingParam}` })
|
|
}
|
|
|
|
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 {
|
|
return res.status(400).json({ error: 'Érvénytelen link' })
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Internal Server Error' })
|
|
}
|
|
}
|