This repository was archived by the owner on Feb 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (47 loc) · 1.3 KB
/
server.js
File metadata and controls
57 lines (47 loc) · 1.3 KB
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
'use strict';
var express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cons = require('consolidate'),
app = express();
app.engine('html', cons.lodash);
// view engine setup
app.set('views', path.join(__dirname, 'public'));
app.set('view engine', 'html');
// middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// connects to database
require('./initializers/database')
.connect()
.then(function() {
// setup routes
require('./initializers/routes')(app);
// setup helpers
require('./initializers/helpers').reload();
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// will print stacktrace
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
message: err.message,
error: err.stack
});
});
if(app.get('env') !== 'test') {
app.listen(process.env.MOCK_PORT || 3000);
}
})
.catch(function(err) {
console.log(err.message);
console.log(err.stack);
process.exit(1);
});
module.exports = app;