Prepare changelog for 21.45.0
[gitter.git] / server / websockets.js
blob7628a8d7c76c2051ff620e2b00d2e48713355bbc
1 'use strict';
3 var env = require('gitter-web-env');
4 var winston = env.logger;
5 var nconf = env.config;
6 var express = require('express');
7 var bayeux = require('./web/bayeux');
8 var appVersion = require('gitter-app-version');
9 var http = require('http');
10 var shutdown = require('shutdown');
11 var serverStats = require('./utils/server-stats');
12 var onMongoConnect = require('gitter-web-persistence-utils/lib/on-mongo-connect');
14 winston.info('Starting http/ws service');
16 var app = express();
17 var server = http.createServer(app);
19 require('./web/graceful-shutdown').install(server, app);
21 require('./web/express').installSocket(app);
23 app.get('/', function(req, res) {
24   res.send('Nothing to see here. Move along please. ' + appVersion.getVersion());
25 });
27 app.get('/api/private/health_check', require('./api/private/health-check'));
28 app.get('/api/private/health_check/full', require('./api/private/health-check-full'));
30 require('./event-listeners').install();
32 var port = nconf.get('PORT') || nconf.get('ws:port');
34 bayeux.attach(server);
36 onMongoConnect(function() {
37   // Listen to the port
38   serverStats('websockets', server);
40   server.listen(port, undefined, nconf.get('ws:backlog'), function() {
41     winston.info('Websockets listening on port ' + port);
42   });
43 });
45 shutdown.addHandler('websockets', 10, function(callback) {
46   server.close(function() {
47     callback();
48   });
49 });