-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (46 loc) · 1.84 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var express = require('express')
var app = express()
var mongoose = require('mongoose')
var http = require('http')
var fs = require('fs')
var bodyParser = require('body-parser')
var port = process.env.PORT || 1337
var VehiclesController = require('./controllers/vehicles')
var HomeController = require('./controllers/home')
var logger = require('./middlewares/logger')
var headers = require('./middlewares/headers')
// ----------------------------------------------------------------------
// view engine setup
// ----------------------------------------------------------------------
app.set('views', './views')
app.set('view engine', 'ejs')
// ----------------------------------------------------------------------
// mongoose
// ----------------------------------------------------------------------
mongoose.Promise = global.Promise
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/test')
var db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:'))
// ----------------------------------------------------------------------
// middlewares
// ----------------------------------------------------------------------
app.use(bodyParser.json())
app.use(logger)
app.use(headers)
// ----------------------------------------------------------------------
// controllers
// ----------------------------------------------------------------------
app.use('', HomeController)
app.use('/api', VehiclesController)
// ----------------------------------------------------------------------
// create server
// ----------------------------------------------------------------------
if (!process.env.PORT) {
http.createServer(app).listen(port, function () {
console.log('motormatch listening on port ' + port)
})
} else {
app.listen(port, app, function () {
console.log('motormatch listening on port ' + port)
})
}