Closed grubshka closed 5 years ago
Why was this closed? Does it do what's intended?
Not at all, it was a mistake. I had problems making the module properly, so I decided to do it simpler :
validateUrl.js :
import normalizeUrl from 'normalize-url';
var regUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/
export default function validateUrl(url) {
if (!regUrl.test(url)) throw new Error(url + ' is not a valid URL');
return normalizeUrl(url);
}
mySchema.js
const ProxySchema = new Schema(
{
url: {
type: String,
required: true,
unique: true,
validate: validateUrl
},
This should fix the error.