Add support for all URL schemas. Resolves #195

This commit is contained in:
poeti8 2019-07-10 19:05:16 +04:30
parent cd49395c02
commit b94eaefd0d

View File

@ -74,7 +74,8 @@ exports.validateUrl = async ({ body, user }, res, next) => {
// Validate URL
const isValidUrl = urlRegex({ exact: true, strict: false }).test(body.target);
if (!isValidUrl) return res.status(400).json({ error: 'URL is not valid.' });
if (!isValidUrl && !/^\w+:\/\//.test(body.target))
return res.status(400).json({ error: 'URL is not valid.' });
// If target is the URL shortener itself
const { host } = URL.parse(addProtocol(body.target));