-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (60 loc) · 2.01 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
/**
* Module dependencies.
*/
var fs = require('fs');
var http = require('http');
var https = require('https');
var express = require('express')
, path = require('path')
, streams = require('./app/streams.js')();
var favicon = require('serve-favicon')
, logger = require('morgan')
, methodOverride = require('method-override')
, bodyParser = require('body-parser')
, errorHandler = require('errorhandler');
var Connections = require('./app/model/connections');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var app = express();
//moongo db connection
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test0');
var query= {'status': 1};
var update = {'status': 0};
Connections.update(query,update,{upsert: false , multi: true}, function(err, doc){
if (err)
{
console.log(err);
}
});
//Connections.collection.drop();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
}
// routing
require('./app/routes.js')(app, streams);
var httpServer = http.createServer(app).listen(app.get('port'));
var httpsServer = https.createServer(credentials, app).listen(3005);
/*httpServer.listen(8080);
httpsServer.listen(8443);
var server = app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
*/
var io = require('socket.io').listen(httpsServer);
io.listen(httpServer,{'pingInterval': 30000, 'pingTimeout': 80000});
/**
* Socket.io event handling
*/
require('./app/socketHandler.js')(io, streams,app);