add get devices routes/controller
This commit is contained in:
parent
64aa61a027
commit
f3842099e1
|
@ -0,0 +1,10 @@
|
||||||
|
const express = require('express');
|
||||||
|
const deviceController = require('./controllers/deviceController');
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router
|
||||||
|
.route('/devices')
|
||||||
|
.get(deviceController.index);
|
||||||
|
|
||||||
|
module.exports = router;
|
|
@ -0,0 +1,13 @@
|
||||||
|
const Device = require('../models/deviceModel');
|
||||||
|
|
||||||
|
function index(req, res) {
|
||||||
|
Device.get((err, devices) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(500).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(devices);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.index = index;
|
|
@ -2,6 +2,7 @@ const express = require('express');
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
|
const apiRoutes = require('./apiRoutes');
|
||||||
|
|
||||||
const { db } = config;
|
const { db } = config;
|
||||||
const app = express();
|
const app = express();
|
||||||
|
@ -16,9 +17,11 @@ mongoose.set('useFindAndModify', false);
|
||||||
|
|
||||||
const mongodb = mongoose.connection;
|
const mongodb = mongoose.connection;
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({ extended: true}));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
|
app.use('/api', apiRoutes);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`trackmyd-api running. PORT: ${port}`);
|
console.log(`trackmyd-api running. PORT: ${port}`);
|
||||||
});
|
});
|
Loading…
Reference in New Issue