Merge branch '2838-disable-tests-that-use-gitlab-api' into 'develop'
[gitter.git] / server / handlers / index.js
bloba51fd54df7fca4cc7b2989a3bc0a964b36571ab6
1 'use strict';
3 var env = require('gitter-web-env');
4 var express = require('express');
5 var urlJoin = require('url-join');
6 const identifyRoute = require('gitter-web-env').middlewares.identifyRoute;
7 const featureToggles = require('../web/middlewares/feature-toggles');
8 var preventClickjackingMiddleware = require('../web/middlewares/prevent-clickjacking');
9 const exploreRenderer = require('./renderers/explore-renderer');
11 var router = express.Router({ caseSensitive: true, mergeParams: true });
13 router.use('/', /* clickjacking is fine-tuned in the file */ require('./root'));
14 router.use('/logout', preventClickjackingMiddleware, require('./logout'));
15 router.use('/login', preventClickjackingMiddleware, require('./login'));
17 router.get(
18   new RegExp('^/explore(.*)?'),
19   identifyRoute('root-explore'),
20   preventClickjackingMiddleware,
21   featureToggles,
22   function(req, res) {
23     // If logged in and trying to go to `/explore`, redirect to `/home/explore`
24     if (req.user) {
25       var userHomeExploreUrl = urlJoin('/home/explore', req.url.replace(/explore\/?/, ''));
26       res.redirect(userHomeExploreUrl);
27     } else {
28       exploreRenderer.renderExplorePage(req, res);
29     }
30   }
33 router.use('/home', /* clickjacking is fine-tuned in the file */ require('./home'));
34 router.use('/settings', /* clickjacking is fine-tuned in the file */ require('./settings'));
35 router.use('/orgs', /* clickjacking is fine-tuned in the file */ require('./org-pages'));
37 // Serve the service-worker code from the root
38 // `GET /sw.js`
39 require('gitter-web-service-worker/server/sw-static').install(router);
41 router.use('/', /* clickjacking is fine-tuned in the file */ require('./app'));
43 /* Catch all - return 404 error */
44 router.get('/*', function(req, res, next) {
45   return next(404);
46 });
48 // Error Handlers
49 router.use(env.middlewares.errorReporter);
50 router.use(require('../web/middlewares/token-error-handler'));
51 router.use(require('../web/middlewares/express-error-handler'));
53 module.exports = router;