Url Shortener cannot get error

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)
    }
    })
})

link to replit is:

index.js - boilerplate-project-urlshortener - Replit

You have a / in the short_url value

{"original_url":"https://boilerplate-project-urlshortener.craigmarc.repl.co/?v=1682106540526","short_url":"htt/serxe"}

When you GET that it becomes a (non-existing) path https://boilerplate-project-urlshortener.craigmarc.repl.co/api/shorturl/htt/serxe


Instead of rolling your own UUID for the short URL you might want to use a lib or at least something that will work as expected.

You can also simplify your URL validation using the method suggested in the challenge.

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.

thanks

It passes all of the tests now but if i open a new window and use the url
with the short url (https://boilerplate-project-urlshortener.craigmarc.repl.co/1uhjj) I still get the cannot get error:

Cannot GET /1uhjj

Shouldn’t that url bring me to the correct webpage?