-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
77 lines (61 loc) · 1.43 KB
/
Copy pathapp.js
File metadata and controls
77 lines (61 loc) · 1.43 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Module dependencies.
*/
var express = require('express')
, emailroute = require('./routes/email')
, http = require('http')
, creds = require('./creds');
var app = express();
// all environments
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
// development only
if (app.get('env') === 'development') {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.locals.pretty = true;
app.locals.port = 1083;
}
// production only
if (app.get('env') === 'production') {
app.use(express.errorHandler());
app.locals.port = process.env.PORT || 80;
};
/*
* ERROR HANDLING
*/
var logErrors = function(err, req, res, next) {
console.error(err.stack);
next(err);
};
function clientErrorHandler(err, req, res, next) {
if (req.xhr) {
res.send(500, { error: err });
} else {
next(err);
}
}
function errorHandler(err, req, res, next) {
res.status(500);
res.render('error', { error: err });
}
app.use(logErrors);
app.use(clientErrorHandler);
app.use(errorHandler);
process.on('uncaughtException', function(err) {
console.log('process died ', err);
});
/**
* Routes
*/
app.post('/email', emailroute.sendmail);
app.get('/heartbeat', function(req, res) {
res.json(200, { message: 'Alive'});
})
/**
* Start Server
*/
http.createServer(app).listen(app.locals.port, function(){
console.log('Server listening on port ' + app.locals.port);
});