This commit is contained in:
skidoodle 2023-12-13 12:36:21 +01:00
parent 8ddc6cb182
commit 603a32b067
2 changed files with 11 additions and 14 deletions

View file

@ -14,18 +14,15 @@ export default async function handler(
return res.status(400).json({ error: `Hiányzó paraméter: ${MissingParam}` })
}
const secure = req.headers['x-forwarded-proto'] === 'https'
const protocol = secure ? 'https' : 'http'
const address = req.headers.host
if (!link.startsWith(`${protocol}://${address}`)) {
return res.status(400).json({ error: 'Érvénytelen link' })
}
try {
const response = await fetch(link, { method: 'HEAD' })
const status = response.status
res.status(200).json({ status })
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' })
}