Skip to content

Instantly share code, notes, and snippets.

@robertz
Created February 24, 2018 02:12
Show Gist options
  • Save robertz/252d0619dab26514a6779477f52468be to your computer and use it in GitHub Desktop.
Save robertz/252d0619dab26514a6779477f52468be to your computer and use it in GitHub Desktop.
serverMiddleware express handler
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