diff --git a/client/public/index.html b/client/public/index.html index 17aed91..ef30f7c 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -3,7 +3,7 @@ - MERN_STACK + MERN Application diff --git a/server/controllers/controller.js b/server/controllers/controller.js index 4ea98aa..afb0d49 100644 --- a/server/controllers/controller.js +++ b/server/controllers/controller.js @@ -2,16 +2,15 @@ import Example from './../models/model.js'; const getExamples = (request, response) => { // what is .find() ??? ---> https://mongoosejs.com/docs/queries.html - Example.find((error, allExamples) => { + Example.find((error, data) => { if (error) { console.log(`❌ ${error}`); return response.status(404).json(error); // 404 not found + catched error -> send to client + } else { + console.log('✅ -FOUND- :', data); + return response.status(200).json(data); // 200 ok + array of documents -> send to client } - // more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html - - console.log('✅ -FOUND- :', allExamples); - return response.status(200).json(allExamples); // 200 ok + array of couments -> send to client }); }; diff --git a/server/routes/route.js b/server/routes/route.js index c917c18..98c7875 100644 --- a/server/routes/route.js +++ b/server/routes/route.js @@ -1,13 +1,12 @@ import express from 'express'; import getExamples from './../controllers/controller.js'; // import request & response function + const router = express.Router(); // initialize router /* 1st param = extended path location 2nd param = request & response function - - current link: http://localhost:8080/examples */ -router.get('/examples', getExamples); +router.get('/examples', getExamples); // current path: http://localhost:8080/examples export default router;