forked from open-city/recycling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (52 loc) · 1.64 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
var express = require('express')
, bodyParser = require('body-parser')
, fs = require('fs')
, hbs = require('hbs')
, http = require('http')
, mongoose = require('mongoose')
, morgan = require('morgan')
, compress = require('compression')
, routes = require('./routes')
, reports = require('./routes/reports')
, locations = require('./routes/locations')
, fauxAuth = require('./middleware/staging-auth')
;
var app = express();
var env = app.get('env');
var config = require('./config/config')[env];
var dbCnx = process.env.MONGOLAB_URI || config.db;
var db = mongoose.connect(dbCnx);
var port = process.env.PORT || config.port || 3000;
// memjs reads appropriate env variables by default.
// zero configuration necessary
app.set('view engine','ejs');
app.engine('html', hbs.__express);
app.use(compress());
app.use(express.static('public'));
app.set('port', port)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
switch (app.get('env')) {
case 'development':
app.use(morgan('dev'));
break;
case 'staging':
app.use(fauxAuth);
break;
default:
app.use(morgan('combined'));
break;
}
app.use(require('./routes/index.js'));
app.get('/reports/count.json', reports.count);
app.get('/reports/:id.json', reports.show);
app.get('/reports.json', reports.index);
app.post('/reports.json', reports.create);
app.get('/locations.json', locations.index);
app.get('/locations/count.json', locations.count);
app.use(require('./routes/wards.js'));
http.createServer(app).listen(port, function(){
console.log('Express server listening on port ' + app.get('port'))
})