-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
36 lines (29 loc) · 1011 Bytes
/
app.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
//-- REQUIRES --//
const express = require('express')
const app = express()
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const promises = require('bluebird')
//-- LOCAL REQUIRES --//
require('./models/all')
const routes = require('./routes')
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
// Connect to the database
mongoose.connect('mongodb://wine_tracker_db:27017/db')
// Use bluebird promises
mongoose.Promise = promises
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
})
// Mount the api sub app
app.use('/api', routes)
// Serve the front end app
app.use(express.static('pub/dist'))
// Start listening on port 3000
app.listen(3000)