-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (39 loc) · 1.1 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
'use strict';
var _ = require('lodash');
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var app = express();
//Standard configurations and middleware
app.engine('html', require('ejs').renderFile);
app.set('port', process.env.PORT || 3000);
//
if (app.get('env') !== 'production') {
app.set('views', 'views');
} else {
app.set('views', 'production/views');
}
app.set('view engine', 'html');
app.use(bodyParser.urlencoded());
//Delivers static content depending on environment
require('routers/static_router')(app);
// Logging
if (app.get('env') !== 'production') {
app.use(morgan('dev'));
}
app.use('/api/*', function (req, res, next) {
res.send(404);
});
//Renders SPA entry point
app.get('/*', function (req, res, next) {
res.render('index');
});
//Error handler
app.use(function (err, req, res, next) {
console.log(err);
console.log(err.stack);
res.send(500, err);
});
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port') + ' in ' + app.get('env') + ' mode.');
});