-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
65 lines (48 loc) · 1.55 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
54
55
56
57
58
59
60
61
62
63
64
65
///////////////////////////////
// DEPENDENCIES
////////////////////////////////
// Init .env vars
require("dotenv").config();
const { PORT, MONGODB_URI } = process.env;
// const PORT = process.env.PORT
// const MONGODB_URI = process.env.MONGODB_URI
const express = require("express");
const app = express();
// Add in mongoose
const mongoose = require('mongoose');
// My controllers
// const peopleController = require('./controllers/people-controller')
const { breweries, people } = require('./controllers')
// Cors and morgan
const cors = require("cors");
const morgan = require("morgan");
///////////////////////////////
// DATABASE CONNECTION
////////////////////////////////
mongoose.connect(MONGODB_URI);
// Connection Events
mongoose.connection
.on("open", () => console.log("This is my awesome amazing connection man"))
.on("close", () => console.log("Your are disconnected from mongoose :'("))
.on("error", (error) => console.log(error));
///////////////////////////////
// MIDDLEWEAR
////////////////////////////////
app.use(express.json()); //parse json
app.use(cors()); //We now pray to whatever higher power or God we have that this works
app.use(morgan("dev"));
app.use('/people', people);
app.use('/breweries', breweries);
///////////////////////////////
// ROUTES
////////////////////////////////
// create a test route
app.get("/", (req, res) => {
res.send("Hello world");
})
///////////////////////////////
// LISTENER
////////////////////////////////
app.listen(PORT, () => {
console.log(`I'm totally listening to you on port ${PORT}`)
})