diff options
-rw-r--r-- | index.js | 16 | ||||
-rw-r--r-- | routes/api/members.js | 21 |
2 files changed, 21 insertions, 16 deletions
@@ -8,22 +8,6 @@ const app = express(); // Init middleware // app.use(logger); -// Gets all members -app.get('/api/members', (req, res) => res.json(members)); - -// Get single member -app.get('/api/members/:id', (req, res) => { - const found = members.some(member => member.id === parseInt(req.params.id)); - - if(found) { - res.json(members.filter(member => - member.id === parseInt(req.params.id))); - } else { - res.status(400).json({ msg: `No member with the id of ${req.params.id}` - }); - } -}); - // Set static directory app.use(express.static(path.join(__dirname, 'public'))); diff --git a/routes/api/members.js b/routes/api/members.js index e69de29..d1c3bf9 100644 --- a/routes/api/members.js +++ b/routes/api/members.js @@ -0,0 +1,21 @@ +const express = require('express'); +const router = express.Router(); + + +// Gets all members +router.get('/api/members', (req, res) => res.json(members)); + +// Get single member +router.get('/api/members/:id', (req, res) => { + const found = members.some(member => member.id === parseInt(req.params.id)); + + if(found) { + res.json(members.filter(member => + member.id === parseInt(req.params.id))); + } else { + res.status(400).json({ msg: `No member with the id of ${req.params.id}` + }); + } +}); + + |