forked from open-city/recycling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1.37 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
const express = require('express')
, bodyParser = require('body-parser')
, http = require('http')
, mongoose = require('mongoose')
, compress = require('compression')
, logger = require('logfmt')
, reports = require('./routes/reports')
, locations = require('./routes/locations')
;
const app = express()
, config = require('./config/public/config.json');
if (!process.env.MONGO_URI) {
console.error('MONGO_URI environment variable must be set')
process.exitCode = 1
}
const dbCnx = process.env.MONGO_URI
, db = mongoose.connect(dbCnx)
, port = process.env.PORT || 3000
// memjs reads appropriate env variables by default.
// zero configuration necessary
app.set('view engine','ejs');
app.engine('html', require('ejs').renderFile);
app.use(compress());
app.use(express.static('public'));
app.use(express.static('config/public'));
app.set('port', port)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
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);
http.createServer(app).listen(port, function() {
logger.log({status: 'info', msg: 'server listening', port: port});
});