mirror of
https://github.com/comatory/fb2iCal
synced 2024-12-28 01:11:03 +01:00
34 lines
584 B
JavaScript
34 lines
584 B
JavaScript
const FBURLError = () => new Error('Not a valid Facebook URL!')
|
|
|
|
const genericErrorHandler = (err, req, res, next) => {
|
|
console.error(err.stack)
|
|
res
|
|
.status(500)
|
|
.render('error', { error: err.toString() })
|
|
}
|
|
|
|
const checkFBURL = (req, res, next) => {
|
|
const { url } = req.body
|
|
|
|
if (!url) {
|
|
return next(FBURLError())
|
|
}
|
|
|
|
try {
|
|
const FBURL = new URL(url)
|
|
if (!(/facebook/.test(FBURL.hostname))) {
|
|
return next(FBURLError())
|
|
}
|
|
} catch (err) {
|
|
return next(err)
|
|
}
|
|
|
|
|
|
return next()
|
|
}
|
|
|
|
module.exports = {
|
|
genericErrorHandler,
|
|
checkFBURL,
|
|
}
|