Prepare changelog for 21.45.0
[gitter.git] / server / web.js
blob83d730efb3ee4a8494baf45b53c9a6016f68f2aa
1 'use strict';
3 /* Configure winston before all else! */
4 var env = require('gitter-web-env');
5 var winston = env.logger;
6 var nconf = env.config;
7 winston.info('Starting server/web.js');
9 var express = require('express');
10 var http = require('http');
11 var serverStats = require('./utils/server-stats');
12 var onMongoConnect = require('gitter-web-persistence-utils/lib/on-mongo-connect');
13 const installBridge = require('gitter-web-matrix-bridge');
15 var app = express();
17 var server = http.createServer(app);
19 require('./web/graceful-shutdown').install(server, app);
21 require('./web/express').installFull(app);
23 require('./web/passport').install();
25 require('./event-listeners').install();
27 if (nconf.get('ws:startFayeInPrimaryApp')) {
28   var bayeux = require('./web/bayeux');
29   bayeux.attach(server);
32 if (nconf.get('web:startApiInPrimaryApp')) {
33   app.use('/api', require('./api/'));
35 app.use('/api_web', require('./api-web/'));
36 app.use('/', require('./handlers/'));
38 // Final error handlers
39 app.use(env.middlewares.errorReporter);
40 app.use(require('./web/middlewares/express-error-handler'));
42 require('./workers').listen();
44 var port = nconf.get('PORT');
46 if (!process.env.DISABLE_API_WEB_LISTEN) {
47   onMongoConnect(function() {
48     serverStats('web', server);
50     server.listen(port, undefined, nconf.get('web:backlog'), function() {
51       winston.info('Listening on ' + port);
52     });
53   });
56 if (!process.env.DISABLE_MATRIX_BRIDGE) {
57   // Install the Gitter <-> Matrix bridge
58   installBridge();
61 module.exports = server;