forked from blackboard/BBDN-SignUp-List
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
111 lines (94 loc) · 3.87 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var express = require('express');
var config = require('./config/config');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('cookie-session');
var index = require('./controllers/routes/index');
// var systems = require('./controllers/routes/systems');
var courses = require('./controllers/routes/courses');
var lists = require('./controllers/routes/lists');
var logs = require('./controllers/routes/logs');
var rest = require('./controllers/routes/rest');
var dataSync = require('./controllers/routes/datasync');
var debug = (config.debugMode === 'true')
//set up mongoose
//determine db path
var db = process.env.MONGO_URI || config.test_db;
// Bring Mongoose into the app
var mongoose = require( 'mongoose' );
// Create the database connection
if (debug) console.log("[SERVER.JS]:db: ", db);
mongoose.connect(db);
// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open to ' + db );
});
// If the connection throws an error
mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error: ' + err);
});
// When the connection is disconnected
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
});
// If the Node process ends, close the Mongoose connection
process.on('SIGINT', function() {
mongoose.connection.close(function () {
console.log('Mongoose default connection disconnected through app termination');
process.exit(0);
});
});
var app = express();
//added to enable Heroku to handle proper SSL termination
app.enable('trust proxy');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
name: 'signuplistv1',
secret: '282r5O>Dg0hu?A4',
resave: false,
saveUninitialized: true
}))
app.use(express.static(path.join(__dirname, '/public')));
app.use('/datetimepicker', express.static(path.join(__dirname, '/node_modules/angular-bootstrap-datetimepicker/src/')));
app.use('/moment', express.static(path.join(__dirname, '/node_modules/moment')));
app.use('/ask', express.static(path.join(__dirname, '/bower_components/angular-spinkit/build')));
app.use('/dialogs', express.static(path.join(__dirname, '/bower_components/angular-dialog-service/dist')));
app.use('/uib', express.static(path.join(__dirname, '/node_modules/angular-ui-bootstrap')));
app.use('/ngSanitize', express.static(path.join(__dirname, '/node_modules/angular-sanitize')));
app.use('/ngCsv', express.static(path.join(__dirname, '/node_modules/ng-csv/build')));
app.use('/ngclipboard', express.static(path.join(__dirname, '/node_modules/ngclipboard/dist')));
app.use('/ngtranslate', express.static(path.join(__dirname, '/node_modules/angular-translate/dist')));
app.use('/', index);
// app.use('/systems', systems);
app.use('/courses', courses);
app.use('/lists', lists);
app.use('/logs', logs);
app.use('/api', rest);
//app.get('/data-sync/:id', dataSync.regListener);
// 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 handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
console.log('error ' + res.status + ': ' + err.message + '<br />' + err.stack);
res.write('error ' + res.status + ': ' + err.message + '<br />' + err.stack);
res.send();
});
module.exports = app;