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');
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);
56 if (!process.env.DISABLE_MATRIX_BRIDGE) {
57 // Install the Gitter <-> Matrix bridge
61 module.exports = server;