Don't perform dns lookup for Url Shortener project?

My app was behaving as specified as far as I can tell, but I wasn’t able to pass the FCC tests. I finally passed the tests after finding the solution mentioned in this thread.

[URL Shortener Project] Everything works, but failing two tests

The solution is simply not to use the dns lookup. If this is still the case (seems like it since I passed the tests after not doing dns lookup), then updating the Hint that explicitly mentions about the use of dns.lookup would be very helpful.

Thanks.

Hello there,

As mentioned in the linked post, the issue has been resolved, and it is perfectly possible to pass the tests using dns.lookup.

However, we cannot help debug why your code did not pass, if you do not share your code. Would you mind sharing what you originally had?

Thank you for your help. So, I must be doing something wrong with the dns lookup. I’m not getting the error messages I was getting before in my repl.it console, but still not passing the tests.

Thank you, for sharing your code. There is a common issue:

 const s = req.body.url
  //must start with http:// or https://
  if (s.substring(0,7) !== 'http://' &&
      s.substring(0,8) !== 'https://') {
      return res.json({'error': 'invalid url'})
  }
  // next()
  const host = s.substring(s.indexOf('//')+2)
  dns.lookup(host, err => {

dns.lookup expects the first argument to be only the hostname of the address. You are making the logic too complex, anyway.

Hope this helps

Ah! Of course. I wasn’t thinking at all about the other stuff like port, path, and search params that could be part of a passed url. I completed the project using
new URL(req.body.url)

Thanks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.