E-commerce application REST API

I cant get the example project running given to us in the project file.

When I run the server and go to the localhost address I recieve a “cannot get /” response.

1 Like

I haven’t built it locally myself but if you look through the source-code in the server directory (and subdirectories) you will find which routes the server is responding to. I didn’t see anything responding to the root-path (’/’) on a quick look. The file index.js under loaders loads up the route js-files from the /routes directory. If you look in those files you will see the routes. For example ‘/api/products’ is one that is used. Try to call up those routes and see if it works. Project is a bit involved so to get full functionality will require starting up a database and likely some more configuration (env-variables for example). I also only discussed the server routes since you mentioned server.

Edit: Follow the instruction in README.md to build the project and that includes instructions to start it up locally.

Correction to my last response. The ‘/api/products’ endpoint is for the fullstack version of the project. For the backend (REST API) version you can use ‘/products’ on the correct port of localhost.

here is my version of the api live here
https://ecommerce-rest-api-codecademy.herokuapp.com/

i have deployed swagger as well , but need to add more functions to the documentation Swagger UI.
This is the git version : GitHub - asmafarhat2006/ecommerce-rest-api

It still requires alot of additions but i have done the basic requirements

1 Like

I tried a couple of GET endpoints and right after that the app seems to be down (including the docs). I would check the heroku logs for some troubleshooting info. Perhaps there is something in the error handling that caused the outage.

which endpoints did you check .
ok ill check .thanks for checking and notifing

it just gets down and then restarts again .
and gives me this error on my api call :

Failed to fetch.
Possible Reasons:

  • CORS
  • Network Failure
  • URL scheme must be “http” or “https” for CORS request.

its working perfectly on my local machine , and through postman.

And strangely there is no error in heroku logs

I tried GET / endpoint first. Got a JSON response from API. Then GET /users (just with chrome). That one is not accessible (as expected). Then back to GET / (now it’s not working). If server restarts there should be something in heroku logs. Maybe check log settings.

The point was I could not get it to run locally so I was hoping someone else could try.

It doesn’t matter now because I just skipped this task and continued on with the rest of the course. But I am still of the belief that the project file given to us was faulty and the task itself wasn’t very instructive or useful.

@mike7127143742
its working now, there was a problem with DB configuration .
I added production rules to it and its working fine now. :grinning:

1 Like

Hi everyone,
Here is my e-commerce-api project deployed to www.heroku.com
Project Link: e-commerce-api-node.
I need to document more routes, there are more routes than documented with swagger
Any feedbacks are appriciated.

Happy hacking

Hello everyone I have finally managed to complete this project now,

Project-Link: Live
Github: Code

For locally I had given some dummy values inside the DB and they worked, but as for doing that on the Heroku DB got a bit lazy, so I have left that out lol might do it sometime later just cant come up with dummy values. Nonetheless this project was great and has made us really go into depth and challenged us (well me in particular) on Backend work and yes I am loving it!

Hey :grinning:, here is my completed Ecommerce REST API project (backend only). It is for a ukulele shop, the database has fake data prefilled to test out.

Swagger UI Link
GitHub page

I found the project enjoyable and quite frustrating at times but really satisfying at the end with everything working. My file structure is nothing like the example solution, which was quite confusing at first glance, but something I might put into practice on the next ecommerce project.

Any questions/feedback welcome.

1 Like

Can you please give more information in README file how to make the solution work, more details please, not everybody has the same knowledge as you guys have, would be better if there will be a video explanation. I really cannot understand some things and such an explanation would make me understand how that works.

You can submit this as a feedback to Codecademy staff if you like. I think it’s a good suggestion. There are several parts that have to be configured (such as the database and environmental-variables) to get this example solution project working and I think a video of it is a good idea.

Hey! I’m about halfway through the project and structure is a lot more like yours than than it is in the provided solution which is reasurring.

The endpoints seem to cover every possible request so as long as the database updates I think it’s great work! Would be nice to see how that ukulele shop plays out!

For me the real challenge started with password and authentication as it seems that had not been covered almost at all in the path apart from a few convoluted tutorials. I note that you encrypted the passwords yourself is that something you researched yourself?

I think they advised using passport which is supposedly easier but again not something they had actually showed how to use!

Hey, thanks for your feedback :+1: Hope your project is going ok so far.

Yeah you don’t really fully learn about the project file structure until after the project, same with authentication and passport. I wanted to stick with what I knew. The solution structure is fairly tricky to understand at first, especially if you haven’t looked at classes for a while, but it slowly makes sense and makes your code cleaner. I left out the authentication because I just didn’t understand it at the time. Having done a lot of research, I understand it a lot better and am currently implementing it.

Passport has several ‘strategies’ it uses for authentication. The single sign on strategies are good, those are the ones that use google, facebook etc. The local strategy uses a username and password sign in.

I think the best way to check if a user is authorised on certain routes is to use a Json Web Token (JWT). You can create one right after a user successfully logs in and then save it to a httpOnly cookie which protects it against security risks. You can store some data in the cookie like a user id which is encrypted and then verified for each route. I found this video Learn JWT in 10 Minutes with Express, Node, and Cookie Parser really helpful.

The password encryption I did a lot of research on yeah, the most secure way is hashing and salting. If you just hash you get the same output given the same input, salting adds a random set of characters to the hash to make it more unique.

I was recommended by another codecademy user a separate skill path on here called ‘Securing Express Apps’, that might be worth looking at.

I look forward to checking out your finished project, I’ll keep an eye out for it :slight_smile:

Just added my own password authentication and authorisation using JWTs and also a new file structure to this project :+1: