URL Shortener Microservice project

Tell us what’s happening:
This is working on glitch as well as on my localhost but I don’t know why the 2nd and 3rd test cases are failing.
Any help, please.
Thanks.

Your project link(s)

solution: Glitch :・゚✧

Your browser information:

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

Challenge: URL Shortener Microservice

Link to the challenge:

This is not right

const noHttpUrl = urlbody.replace(/https?:\/\//, "");
  dns.lookup(noHttpUrl, (err,address) => {

because the passed req.body.url could contain more than just the hostname after the protocol, such as query parameters, and you need to pass just the hostname portion to the dns lookup. I used URL object to test for both the protocol and hostname.
Also, I don’t think you want to do this

return res.redirect('http://' + data.url);

The original protocol may not be http. I stored the full req.body.url and used this for redirect.

2 Likes

I appreciate your help and will try again with your correction.
Thanks.

It worked!
Thanks for your help.

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