Hi
I am unable to complete all the test cases. The test for invalid url is failing. However I have use URL and Dns module to validate the url but test is not being passed.
My project link is here:
solution: https://shortit-fcc.herokuapp.com
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36
.
Challenge: URL Shortener Microservice
Link to the challenge:
Code for api is as per below:
app.post('/api/shorturl', async function(req,res){
const fullUrl = req.body.url;
try {
const myURL = new URL(fullUrl);
dns.lookup(myURL.host,async (err,address,family)=>{
if(err){
res.json({error: 'invalid url'});
}
const record = new UrlShort({original_url:fullUrl});
await record.save();
//console.log(record);
res.json({original_url:record.original_url,short_url:record.short_url})
})
} catch (error) {
//console.log(error);
res.json({error: 'invalid url'});
}
});