Here is my code for post request in url shortner microservice .It works fine in rel repository but when i paste the repl link to check in solution link then i could not pass the test .
app.post('/api/shorturl/new', (req,res)=>{
console.log(req.body.url)
let fs=/\//ig
// regex condition t oremove https from url
let regex= /^(https)\:\/\//ig
// replacing https to empty string
let host =req.body.url.replace(regex,'').split('/')
// // handling the invalid urlusing dns inbuilt module
dns.lookup(host[0],async (err, address, family)=>{
if(err || host.length == 0 ) {
return res.json({ error: 'invalid url' })
}
else{
let exist=await Shorturl.findOne({original_url:req.body.url})
if(exist){
res.json({
original_url: exist.original_url,
short_url: exist.short_url
})}
else{
let url={original_url:req.body.url,short_url:randomValue()}
createUrl(url)
res.json(url)}
}
})
})
Your project link(s)