-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
44 lines (35 loc) · 1.06 KB
/
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
37
38
39
40
41
42
43
44
'use strict';
const express = require('express'),
app = express(),
load = require('express-load'),
db = require('./app/mongo/mongoConnection'),
url = process.env.MONGODB_URI ? process.env.MONGODB_URI : 'mongodb://localhost:27017/cookbook',
bodyParser = require('body-parser'),
ua = require('universal-analytics'),
compression = require('compression')
app.use(compression());
app.use(ua.middleware(process.env.GOOGLE_ANALYTICS, {
cookieName: '_ga'
}));
app.get(['/', ''], function(req, res) {
res.status(200).sendFile(__dirname + '/public/index.html')
req.visitor.pageview("/home").send()
})
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
load('routes', {
cwd: 'app'
}).then('mongo').then('model').into(app)
process.db = db;
db.connect(url, function(err) {
if (err) {
console.log('We can\'t cook and to connect to mongo...')
process.exit(1)
} else {
app.listen(process.env.PORT || 3000, function() {
console.log('Let\'s cook...')
})
}
})