Hello!
So I’ve finally finished my url Shortener and I’d really appreciate some feedback. I also have some questions since I’ve just started to get familiar with coding the backend.
Do I need the nodemon.js file for anything? As far as I can tell I shouldn’t need it but without it, my last 2 tests would fail.
How should I have known that the post request would be a JSON object with this structure:
{
"url":"https://www.goodreads.com/"
}
Initially, when I tested things in postman I just sent plain text in the body so I didn’t understand why I was failing the tests.
That’s why I also changed the input id and name of the input form so that I would receive the same key and be able to destructure it.
In the urlNumber.js I have these 2 :
router.post('/:urlIndex', redirectToAdress);
router.get('/:urlIndex', redirectToAdress);
That’s because I didn’t know how to make the form action work with the get method. The get would add the ? separator and my query after that. Even though I needed the /api/shorturl/:[data-from-get-input] structure it would give me the /api/shorturl?[data-from-get-input] structure. That’s why I’ve used the post method. Then I realized that the browser defaults to the get method when you type the adress directly so I’ve also added the 2cnd router.
Live link: https://boilerplate-project-urlshortener-1.flaxi-cj.repl.co
Replit: https://replit.com/@flaxi-cj/boilerplate-project-urlshortener-1#.replit
GitHub:GitHub - flaxi-cj/boilerplate-project-urlshortener: A boilerplate for a freeCodeCamp project.