Created
February 24, 2018 02:12
-
-
Save robertz/252d0619dab26514a6779477f52468be to your computer and use it in GitHub Desktop.
serverMiddleware express handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const mongoose = require("mongoose"); | |
const cors = require("cors"); | |
const apiController = require("./controllers/api"); | |
// Create express instnace | |
const app = express(); | |
// Setup mongoose | |
mongoose.Promise = global.Promise; | |
mongoose.connect("mongodb://rsanchez:[email protected]:27017/node-billz"); | |
mongoose.connection.on("error", err => { | |
console.error(err); | |
console.log( | |
"MongoDB connection error. Please make sure MongoDB is running." | |
); | |
process.exit(); | |
}); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
/** | |
* API routes | |
*/ | |
app.get('/user/:userid/payees', apiController.getPayees); | |
// Export the server middleware | |
module.exports = { | |
path: "/api", | |
handler: app | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment