This repository was archived by the owner on May 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (40 loc) · 1.38 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Include Server Dependencies
import express from "express";
import bodyParser from "body-parser";
import logger from "morgan";
import mongoose from "mongoose";
import routes from "./server/controllers";
import DatabaseSeeder from "./server/seed-data/seed";
// Create Instance of Express
var app = express();
// Sets an initial port. We'll use this later in our listener
var PORT = process.env.PORT || 3000;
// Run Morgan for Logging
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
app.use(express.static("./public"));
// -------------------------------------------------
// MongoDB Configuration configuration (Change this URL to your own DB)
Promise = require('bluebird');
mongoose.Promise = Promise;
mongoose.connect("mongodb://localhost/SodaApp");
var db = mongoose.connection;
db.on("error", function(err) {
console.log("Mongoose Error: ", err);
});
db.once("open", function() {
let seeder = new DatabaseSeeder();
seeder.runSeed();
console.log("Mongoose connection successful.");
});
// -------------------------------------------------
app.use("/api", routes);
// -------------------------------------------------
// Listener
app.listen(PORT, function() {
console.log("App listening on PORT: " + PORT);
});
export default app;