Back End Development and APIs Projects - URL Shortener Microservice

Test 3 not solved. also req.params.id returns undefined while submitting the solution

app.get('/api/shorturl/:id', (req, res) => {
  console.log(req.params.id);
  res.redirect(urls[req.params.id-1]);
});

solution: boilerplate-project-urlshortener - Replit

Challenge: Back End Development and APIs Projects - URL Shortener Microservice

Link to the challenge:

That’s because your POST route is returning undefined for the ID on that test.

You should log all the route inputs and responses from both routes to track what happens in your code as you run the tests. Doing this, you will find that a valid URL is marked as invalid. To correct the problem, this bit of documentation may be helpful; you will need to very slightly restructure your code.

I mean, its return undefined while submitting the solution, but its working while testing it in browser.

Using your Url Shortner app (https://boilerplate-project-urlshortener.xnin069.repl.co/), try the following using the form on the page.

  1. Submit https://freecodecamp.org/news which is a valid url.
  2. Next, submit https://freecodecamp.org/learn which is a valid url.

Do you get an error on either one? I do. You will soon find that every other time you submit a valid url, your app will respond that it is invalid.

I see. It’s inconsistent. I Just placed regexUrl inside POST callback and it’s solved now. Thanks alot <3

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