Skip to content

Commit

Permalink
Added Logs Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalchhabra37 committed Jul 5, 2022
1 parent 7cf0511 commit 8ec8f79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apiRoutes.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"status": ["active", "inactive", "true","false"],
"role" : "string"
}
},
"/api/logs":{
"description":"Get all logs"
}
},
"POST": {
Expand Down
6 changes: 6 additions & 0 deletions controllers/logController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const Logs = require('../models/logs');

exports.getLogs = async (req, res) => {
let logs = await Logs.find()
res.json(logs)
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ const app = express();
// Body Parser
app.use(express.json());
app.use(express.urlencoded({extended: false}));

// Middleware to log requests
app.use(logger);

// Home Route
app.get('/', (req, res) => res.json(jsonAPiRoutes));
// API Routes
app.use('/api/employees', require('./routes/api.employee'))
app.use('/api/logs', require('./routes/api.logs'))
// ENV
const dbConn = `mongodb+srv://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASS}@${process.env.MONGO_DB_CLUSTER}.hvghisd.mongodb.net/${process.env.MONGO_DB_DB}`
const PORT = process.env.PORT || 5000;
Expand Down
7 changes: 7 additions & 0 deletions routes/api.logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require('express')
const router = express.Router()
const logController = require('../controllers/logController')

router.get('/', logController.getLogs)

module.exports = router;

0 comments on commit 8ec8f79

Please sign in to comment.