forked from cbmsc-diti/mogi-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
100 lines (84 loc) · 2.8 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
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
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, app = express()
, server = http.createServer(app)
, io = require('socket.io')(server, {origins:'*:*'})
, passport = require('passport')
, db = require('./lib/db')
, config = require('./lib/config')
, cookieParser = require('cookie-parser')
, logger = require('morgan')
, methodOverride = require('method-override')
, errorHandler = require('errorhandler')
, bodyParser = require('body-parser')
, exportUtils = require('./lib/exports/exportUtils.js')
//, streams = require('./lib/streams/streams.js')();
, crypto = require('./lib/crypto')
// Express configuration
var allowCrossDomain = function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
};
if (process.env.PORT == null){
console.warn('process.env.PORT is null!');
}
app.set('port', process.env.PORT || 3000);
app.use(logger('dev'));
app.use(allowCrossDomain);
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride());
app.use(passport.initialize());
if ('development' == app.get('env')) {
app.use(errorHandler({dumpExceptions: true, showStack: true}));
}
// Passport configuration
var auth = require('./lib/auth');
app.post('/token', auth.tokenEndpoint);
app.use(require('./lib/config/wizard'));
app.use(require('./lib/users'));
app.use(require('./lib/streams'));
app.use(require('./lib/videos'));
app.use(require('./lib/locations'));
app.use(require('./lib/histories'));
app.use(require('./lib/incidents'));
app.use(require('./lib/reports'));
app.use(require('./lib/groups'));
app.use(require('./lib/heartbeats'));
app.use(require('./lib/batteries'));
app.use(require('./lib/incidentForms'))
app.use(require('./lib/pictures'));
app.use(require('./lib/logreports'));
app.use(require('./lib/exports'));
streams = require('./lib/streams/streams.js')();
require('./lib/streams/socketHandler.js')(io, auth, streams);
app.set('sockets', io.sockets);
app.set('streams', streams);
var option = {force: false};
//if (process.env.NODE_ENV == "test"){
// option["force"] = true;
//}
db.sequelize.sync(option).then(function() {
//if (err) {
// throw err;
//} else {
crypto.crypto_init(function() {
server.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
exportUtils.loadExpireJobs();
});
});
});