Microservices Shortner not passing test

Tell us what’s happening:
Describe your issue in detail here.
Hi, It works fine from my testing however not passing 2nd/3rd items when I submit.
I can register original URL/shortened one in MongoDB with returning JSON format.
Then original URL can be redirected using registered short URL by GET method.
Plz help.
Jason.

Your project link(s)

solution: https://replit.com/@jasonlee23/boilerplate-project-urlshortener-1

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Challenge: URL Shortener Microservice

Link to the challenge:

It’s your validation regular expression:

const regex = new RegExp('^(http:\/\/|https:\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[‌​a-z]{3}\.([a-z]+)?$')

This doesn’t match the URLs you think it does. It’s rejecting valid URLs with route parameters and query strings, like http://www.example.net/article/1, etc., which is what the fCC tests use as valid URLs.

Hey Jeremy,

Thanks for getting back to me. After your suggestion, I have tried dns.lookup method. Then any prefixes with http:// or https:// are told as invalid.
Can you help what I am wrong with dns.lookup?
This really is making me nuts.
Plz help.

Thanks and regards,
J

Here’s the documentation for dns.lookup() (the callback version anyway). You have to give it a hostname as an argument, which from http://www.example.net/article/1 would just be www.example.net. You have to remove and handle any prefixes (like http/https) and any route parameters (like /article/1) in the URL yourself.

The test for invalid URLs is not terribly strict so you could fix your regular expression so that it could pass as well.

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