URL Shortener Microservice don't pass in any test

Hey guys, how’re you? I don’t know what to do anymore I changed my code a lot and there is no way to make pass the tests, below is the link to my code

https://github.com/luizfernandorg/URLShortenerMicroservice/tree/mongoose

I tested the code on my machine and works perfectly, I get the JSON response the way is in the example, bad URLs are rejected, the code update in the case is provided the same url, I don’t know what I need to do. I’ll appreciate any help.

Do you have a link to a running server for this?

is working right now in this link: https://urlshortener.luizfernandorg.repl.co

I notice one thing, I caught the URLs that the tests are sending to my site, and two URLs are for my Replit link like this: https://urlshortener.luizfernandorg.repl.co/, but that URL return as an invalid link, may this is causing the failing tests

I updated the Regular Expression, now is accepting my Replit URL.

This is the address I’m getting from the tests:

https://urlshortener.luizfernandorg.repl.co/?v=1635650054138
https://urlshortener.luizfernandorg.repl.co/?v=1635650054879
ftp:/john-doe.org

I"m getting from the tests those 3 URLs, I tested those first two, I can access the URLs and those are valid they give access to it, and the FTP URL is an invalid URL, I don’t understand, are all three supposed to fail to validate the tests?

I used the dns.lookup(), but this function doesn’t validate those first two URLs, they are valid, those URLs give access to the site.

it says invalid URL why is that?

I updated the Regular Expression, but I don’t know why dns.lookup don’t accept those links above, I can access the URLs without a problem, during the test I notice that dns.lookup don’t accept URLs with “http|https|ftp”, etc. only everything after “://”

I published on Heroku, this is the link https://boiling-spire-01138.herokuapp.com/, but will work for a few moments because Mongo Atlas limitation, I don’t have the application ip

When I submit your Heroku app and look at the network tab in the browser I see CORS blocking.

We can’t see your code on Heroku so if you need help link to your repository with the code, or keep using replit.


The FTP URL is the one that is supposed to fail validation. Technically, it’s the only invalid URL that is tested against so just checking the protocol would be enough.

You can get the protocol and hostname using the URL constructor.

new URL('https://www.freecodecamp.org/test').protocol
'https:'

new URL('https://www.freecodecamp.org/test').hostname
'www.freecodecamp.org'

The dns method takes a hostname which is just the domain name and top-level domain, e.g. for this URL https://www.freecodecamp.org/test the hostname is freecodecamp.org.

2 Likes

a huge thanks to everyone that took your time to help, lasjorg indeed was the cors() that was missing in the code, all tests passed, Thank you!

1 Like

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