setting up route with proper mini-apps with express.Router() and app.use()
This commit is contained in:
@@ -10,7 +10,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
last_name: DataTypes.STRING,
|
||||
email: DataTypes.STRING,
|
||||
age: DataTypes.INTEGER,
|
||||
phone: DataTypes.INTEGER,
|
||||
phone: DataTypes.BIGINT,
|
||||
address: DataTypes.STRING,
|
||||
city: DataTypes.STRING,
|
||||
state: DataTypes.STRING,
|
||||
|
||||
+20
-18
@@ -1,19 +1,21 @@
|
||||
module.exports = function(app) {
|
||||
|
||||
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);
|
||||
const express = require('express'),
|
||||
router = express.Router();
|
||||
|
||||
// Delete a Donor with Id
|
||||
app.delete('/api/donors/:DonorId', donors.delete);
|
||||
|
||||
// // Update a Donor with Id
|
||||
// app.put('/api/donors/:DonorId', donors.update);
|
||||
}
|
||||
const donors = require('../controllers/donors.controller.js');
|
||||
|
||||
// Create a new Donor
|
||||
router.post('/', donors.create);
|
||||
|
||||
// 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;
|
||||
@@ -19,18 +19,19 @@ db.sequelize
|
||||
});
|
||||
|
||||
// force: true will drop the table if it already exists
|
||||
db.sequelize.sync({force: true}).then(() => {
|
||||
console.log('Drop and Resync with { force: true }');
|
||||
const drop_tables = 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
|
||||
router.get('/', function (req, res, next) {
|
||||
app.get('/', function (req, res, next) {
|
||||
res.send('Welcome to the Ucharify API');
|
||||
});
|
||||
|
||||
//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
|
||||
var server = app.listen(port, function () {
|
||||
|
||||
Reference in New Issue
Block a user