adonisjs / env

Framework agnostic environment variables parser and validator
https://docs.adonisjs.com/guides/environment-variables
MIT License
37 stars 10 forks source link

Problem with schema URL validation when using URLS without a TLD #33

Closed ad-on-is closed 6 months ago

ad-on-is commented 1 year ago

Just realized the following

SOMEURL: Env.schema.string({format: 'url'})

if the URL is something like http://someservice:3030, which is the case when using an AdonisJS application with other services and docker-compose, it throws an error.

E_INVALID_ENV_VALUE: Value for environment variable "SOMEURL" must be a valid URL, instead received "http://someservice:3030"

Expected result: http://someservice:3030" should be valid

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

shiny commented 8 months ago

I had the same problem, http://127.0.0.1:3333 is a valid url but http://localhost:3333 is not. that's confusing.

thetutlage commented 8 months ago

This happens because the http://localhost:3333 does not have a tld on it. Here's the docs to allow URLs without tld https://docs.adonisjs.com/guides/environment-variables#url.

Why does it allow http://127.0.0.1:3333? I am not sure, we use https://github.com/validatorjs/validator.js, so maybe there is some exception for IP Addresses to pass the validation rule.

thetutlage commented 6 months ago

Closing since no response from the issue reporter and not actionable as well