-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (39 loc) · 1.45 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
// MODULES =================================================
const express = require('express');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// CONFIGURATION ===========================================
// set port
const port = process.env.PORT || 8080
// mpromise is depreciated, use native es6 Promise
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URL || process.env.MONGOLAB_ORANGE_URI, {
useMongoClient: true
})
// mongoose.connect(process.env.MONGODB_URL || 'mongodb://localhost:27017', {
// useMongoClient: true
// })
// If the Node process ends, close the Mongoose connection
// see: http://theholmesoffice.com/mongoose-connection-best-practice/
process.on('SIGINT', function () {
mongoose.connection.close(function () {
console.log('Mongoose default connection disconnected through app termination')
process.exit(0)
})
})
// parse application/json
app.use(bodyParser.json());
// ROUTES ==================================================
app.use(require('./app/routes'));
app.use('/public', express.static(path.join(__dirname, 'public'), {
fallthrough: false
}));
app.use('/public/build', express.static(path.join(__dirname, 'public/build'), {
fallthrough: false
}));
// START APP ===============================================
app.listen(port, () => {
console.log(`Magic happens on port ${port}`);
});