Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way of validating a certain hostname in URI #2690

Open
Apidcloud opened this issue Oct 19, 2021 · 1 comment
Open

Better way of validating a certain hostname in URI #2690

Apidcloud opened this issue Oct 19, 2021 · 1 comment
Labels
feature New functionality or improvement

Comments

@Apidcloud
Copy link

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 16.9.1
  • module version: 17.4.2
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

How can we help?

This is related to #1965. I am wondering if there is a way of validating whether a given URI has a certain hostname. This would be useful, for instance, to validate social media URIs (e.g., instagram, facebook, twitter). In the thread #1965 it is mentioned that the portion can be verified through some new option introduced in v16, but I couldn't figure out how to do it yet. For now I am relying on regex (see example below), though one could have a custom validation step (using node URL.hostname).

facebook: Joi.string()
  .uri({
    scheme: 'https',
	domain: { 
		// is there a way of checking the hostname here?
	}
   })
  .regex(/https:\/\/(www\.)?facebook\.com\/.*/)
  .optional(),
@hueniverse hueniverse added the feature New functionality or improvement label Dec 2, 2021
@hueniverse hueniverse self-assigned this Dec 2, 2021
@BolajiOlajide
Copy link
Contributor

@hueniverse I'll love to help out with this, let me know if it's something you think I can help with.
Also, let me know if you've got any approach you'd like to me employ.

Thanks.

@hueniverse hueniverse removed their assignment Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants