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

Pass through validator options in oGS options #110

Closed
lukeocodes opened this issue Nov 1, 2020 · 1 comment
Closed

Pass through validator options in oGS options #110

lukeocodes opened this issue Nov 1, 2020 · 1 comment

Comments

@lukeocodes
Copy link

Hey, I'm just trying to understand why http://localhost:3000 is invalid but 127.0.0.1 is valid? Is it the require_tld that it fails on in validator?

'http://localhost:3000/',

Before I opened this I found a mention in validator about exactly this, you can disable require_tld to get localhost to validate.

validatorjs/validator.js#675

Is there space here to allow for passing in validator options through the oGS options? i.e.

    const options = { 
      url: 'http://localhost:3000',
      validator: {
        require_tld: false
      }
    }

    ogs(options)
      .then((data) => {
        const { error, result } = data
        if (error) console.log('error:', error)
        console.log('result:', result)
      })
      .catch((error) => {
        consola.error(error)
      })

WDYT? I can give a PR a go to add this.

@lukeocodes lukeocodes changed the title Why would localhost:3000 be invalid? Pass through validator options in oGS options Nov 1, 2020
@jshemas
Copy link
Owner

jshemas commented Nov 3, 2020

Hello! This is a great idea! I added it in [email protected].

Example:

const ogs = require('open-graph-scraper');

const options = {
  url: 'http://ogp.me/',
  urlValidatorSettings: {
    protocols: ['http', 'https'],
    require_tld: true,
    require_protocol: false,
    require_host: true,
    require_valid_protocol: true,
    allow_underscores: false,
    host_whitelist: false,
    host_blacklist: false,
    allow_trailing_dot: false,
    allow_protocol_relative_urls: false,
    disallow_auth: false,
  },
};

ogs(options)
  .then((data) => {
    const { error, result, response } = data;
    console.log('error:', error); // This is returns true or false. True if there was a error. The error it self is inside the results object.
    console.log('result:', result); // This contains all of the Open Graph results
    console.log('response:', response); // This contains the HTML of page
  });

@jshemas jshemas closed this as completed Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants