This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebSocketApp.js
executable file
·114 lines (93 loc) · 3.53 KB
/
webSocketApp.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
112
113
114
var WebSocketApp = function (app) {
var
express = require('express'),
http = require('http'),
config = require('config'),
log = require(process.env.APP_PATH + "/lib/log"),
controller = require(process.env.APP_PATH + "/lib/controller"),
Auth_Authom = require(process.env.APP_PATH + "/lib/auth/authom").Auth_Authom,
auth = new Auth_Authom();
if (!app) {
app = express();
}
var server = http.createServer(app);
if (!process.env.TESTER) {
global.socketio = require('socket.io').listen(server);
}
app.configure(function () {
if (process.env.NODE_ENV !== 'development') {
app.use(express.logger());
}
else {
app.use(express.logger("dev"));
app.locals.pretty = true;
}
app.set('views', process.env.APP_PATH + '/views');
app.set('view engine', 'jade');
app.locals({
config: config
});
app.set('config', config);
// access.log format (default is full)
// app.use(express.logger({ format: ':method :url' }));
// app.use(expressValidator); //data validator and sanitizer
// standard mvc
// for auth
app.use(express.cookieParser())
.use(express.session({
secret: "string"
})
)
// .use(express.bodyParser()) //no need POST data
.use(express.methodOverride());
auth.initApp(app);
// position our routes above the error handling middleware,
// and below our API middleware, since we want the API validation
// to take place BEFORE our routes
app.use(app.router);
controller.bootControllers(app, '');
//added route for blitz.io (
app.get('/mu-9ff269e7-6ebc7098-352e3887-d5152fd1', function (req, res) {
res.send('42');
});
// middleware with an arity of 4 are considered
// error handling middleware. When you next(err)
// it will be passed through the defined middleware
// in order, but ONLY those with an arity of 4, ignoring
// regular middleware.
app.use(function (err, req, res, next) {
// on development show debug stack
if (process.env.NODE_ENV === 'development' && !process.env.TESTER) {
return next(err); // goto express.errorHandler
}
// check error type
if (!err.hasOwnProperty('code')) {
log.error('500[app]: ' + req.originalUrl + ', error: ' + err.message); // log
// real
// message
err = error(500, 'Unexpexted error occured'); // override message
}
log.error(err.code + ': ' + req.originalUrl + ', error: ' + err.message);
res.status(500);
res.render('info', {
title: 'Unexpected problem (500)'
});
});
app.use(express.errorHandler({
showStack: true,
dumpExceptions: true
}));
// our custom JSON 404 middleware. Since it's placed last
// it will be the last middleware called, if all others
// invoke next() and do not respond.
app.use(function (req, res) {
log.error('404[app]: ' + req.originalUrl);
res.status(404);
res.render('info', {
title: 'Cannot find page (404)'
});
});
});
return server;
};
module.exports.WebSocketApp = WebSocketApp;