I feel like i have been asking too many questions lately but i have been stuck on this for hours and it seems like it should be simple.
I have been working on the Url shortener project and have most of it working except when open another window in the browser and /api/shorturl/<short_url> where short url is a short url in my database i get the error:
Cannot GET /https:/yahoo.com/mnc37g
So the third test is failing.
my get code is as follows which seems ok to me but i guess it isnt because it doesnt work:
app.get("/api/shorturl/:shorturl", (req, res) => {
UrlData.findOne({shortUrl: req.params.shorturl}, function (err, data) {
if (err) return console.log(err);
if (!data) {
return res.json('No URL found')
}
else {
return res.redirect(data.origUrl)
}
})
})
Yup that was it its working perfectly now. I was thinking that was what might be messing it up but never bothered to try to change it. I just ended up using the random string as the short url.