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'));
18 new RegExp('^/explore(.*)?'),
19 identifyRoute('root-explore'),
20 preventClickjackingMiddleware,
23 // If logged in and trying to go to `/explore`, redirect to `/home/explore`
25 var userHomeExploreUrl = urlJoin('/home/explore', req.url.replace(/explore\/?/, ''));
26 res.redirect(userHomeExploreUrl);
28 exploreRenderer.renderExplorePage(req, res);
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
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) {
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;