Back End Development and APIs Projects - URL Shortener Microservice

I am unable to pass the second and third tests for this project.

I think the problem is with my JSON reponse, as the fourth test was also not passing and it got it passing by using response.json instead of response.status(200).response.send(…) (on line 30 of app.controllers.ts). However, when I try and use the response.JSON method on my valid URL to send, my output looks like it is in the acceptable format however is still failing. Please note I am also using TypeScript.

Any help is much appreciated.

replit link

Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Back End Development and APIs Projects - URL Shortener Microservice

Link to the challenge:

Your start script isn’t correct, please update it.

Your URL validation isn’t working. You can use the Node DNS module or a package like valid-url (use the isWebUri method).

When I fix the URL validation your project passes all the tests.

1 Like

Hello, Thank you for taking a look at my code and for your helpful response.

I have changed my starting scripts. I have refactored my URL validation to be more readable and not use regex. I have also used the dns.lookup method however my tests are still not passing.

I have cleaned the URL inputs up to satisfy the requirements for the dns.lookup. I have also ensured, to the best of my knowledge, that the user original URL input matches FCC requirements. I am not sure where I am going wrong to be honest.

Again second and third tests not passing but all appears to be working when using the app.

Any help much appreciated.

Your validation still isn’t working.

You are just overcomplicating this. Use the npm package I linked to and you can validate the URL with one line of code. There is no reason to reinvent the wheel here.

When testing your code open the network tab in the browser, do the submit, and look at the response. As you will see the response you are sending is the catch response.

Some of the over complicating is deliberate for my practice and learning purposes. But yes you are right, the validation still wasn’t working.

I ended up installing the valid-url npm package to valid the URL from the user. Then to make sure the last test passed I added an extra check to ensure that the originally posted URL form the user contained an http or https at the start. All tests now passing.

Thanks so much

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