setting up route with proper mini-apps with express.Router() and app.use()

This commit is contained in:
Arjun Patel
2019-01-04 16:51:27 -08:00
parent 044f947e6d
commit 518840a576
3 changed files with 26 additions and 23 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ module.exports = (sequelize, DataTypes) => {
last_name: DataTypes.STRING, last_name: DataTypes.STRING,
email: DataTypes.STRING, email: DataTypes.STRING,
age: DataTypes.INTEGER, age: DataTypes.INTEGER,
phone: DataTypes.INTEGER, phone: DataTypes.BIGINT,
address: DataTypes.STRING, address: DataTypes.STRING,
city: DataTypes.STRING, city: DataTypes.STRING,
state: DataTypes.STRING, state: DataTypes.STRING,
+20 -18
View File
@@ -1,19 +1,21 @@
module.exports = function(app) { const express = require('express'),
router = express.Router();
const donors = require('../controllers/donors.controller.js');
// Create a new Donor
app.post('/api/donors', donors.create);
// Retrieve all Donor
app.get('/api/donors', donors.findAll);
// Retrieve a single Donor by Id
app.get('/api/donors/:DonorId', donors.findById);
// Delete a Donor with Id const donors = require('../controllers/donors.controller.js');
app.delete('/api/donors/:DonorId', donors.delete);
// Create a new Donor
// // Update a Donor with Id router.post('/', donors.create);
// app.put('/api/donors/:DonorId', donors.update);
} // Retrieve all Donor
router.get('/', donors.findAll);
// Retrieve a single Donor by Id
router.get('/:DonorId', donors.findById);
// Delete a Donor with Id
router.delete('/:DonorId', donors.delete);
// // Update a Donor with Id
// router.put('/api/donors/:DonorId', donors.update);
module.exports = router;
+5 -4
View File
@@ -19,18 +19,19 @@ db.sequelize
}); });
// force: true will drop the table if it already exists // force: true will drop the table if it already exists
db.sequelize.sync({force: true}).then(() => { const drop_tables = true;
console.log('Drop and Resync with { force: true }'); db.sequelize.sync({force: drop_tables}).then(() => {
console.log(`Drop and Resync with { force: ${drop_tables} }`);
}); });
//define a route, usually this would be a bunch of routes imported from another file //define a route, usually this would be a bunch of routes imported from another file
router.get('/', function (req, res, next) { app.get('/', function (req, res, next) {
res.send('Welcome to the Ucharify API'); res.send('Welcome to the Ucharify API');
}); });
//adding routes to Express app //adding routes to Express app
require('./app/routes/donors.route.js')(app); app.use('/api/donors', require('./app/routes/donors.route.js'));
// Create a Server // Create a Server
var server = app.listen(port, function () { var server = app.listen(port, function () {