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