Tell us what’s happening:
I’ve completed the URL Shortening Microservice project, and it works as it’s supposed to, yet two of the four tests are not passing. This happened with he last project, and I was able to solve the issue with a bit of refactoring, but this time I cannot find what seems to be the issue.
Very likely you’re having issues with the dns lookup. Make sure you extract only the hostname from the passed url. FCC tests pass url with a query parameter, something like
https://www.xyz.com/?v=34982873
You need to pass just the hostname portion www.xyz.com to dns.lookup. I created a URL object from req.body.url and pass the hostname urlObj.hostname to dns.lookup method.
I appreciate your help! You were right about the passing just the hostname portion to the dns.lookup. The fact that the FCC tests pass in urls with query parameter totally slipped my mind. Once I implemented the changes you suggested, the tests passed, but another test that had initially passed ended up failing (the error response). To fix this, I added the npm package valid-url, and used the .isWebUri to test the passed in url. Without this, a passed url could be verified by dns.lookup even if, for example, the url has a bunch of spaces at the end.