konsumer / mongoose-type-url

A url field-type for Mongoose schemas
15 stars 6 forks source link

Url normalization #26

Open andrefs opened 3 years ago

andrefs commented 3 years ago

This module uses normalize-url, which by default strips (among other things) the www from the URLs. I had a use case where I did not want this to happen.

I have no idea whether if there is a way for mongoose-type-url to receive additional parameters which would be passed on to configure normalize-url. If this is not possible, at least referring normalize-url in this module's documentation would make it more clear.

konsumer commented 3 years ago

I would recommend just making a new type. The configuration is going to be more complicated than just making a mongoose.SchemaTypes.NormalizedUrl. When I made this, I used String as a base, and you can feel free to use this as a base for yours. As you can see the definition is pretty simple (just a URL-check regex.) You can make it work how you want by making your own type, search & replace for Url to NormalizedUrl and re-implementing validateUrl.

andrefs commented 3 years ago

Yes, thank you, that is more or less the solution I implemented.

I was just suggesting that mentioning normalize-url in mongoose-type-url's documentation would allow users to expect the URL to be normalized and not getting caught by surprise.

Thanks!

konsumer commented 3 years ago

I would be much more "caught by surprise" if the database-type was modifying the URL, and this doesn't seem to be a standard thing at all, so I am hesitant to add it to the docs, as it would be confusing to me if I came across my project made by someone else, and there was stuff about normalize-url. I can link to your mongoose-type though, if you like. Do you have it on github?