Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / handlers / app / index.js
blob91895844b13148bbcef0dd3c6f1d33533ce1e6a2
1 'use strict';
3 const env = require('gitter-web-env');
4 const config = env.config;
5 const express = require('express');
6 const uriContextResolverMiddleware = require('../uri-context/uri-context-resolver-middleware');
7 // var recentRoomService = require('gitter-web-rooms/lib/recent-room-service');
8 // var isPhoneMiddleware = require('../../web/middlewares/is-phone');
9 // var timezoneMiddleware = require('../../web/middlewares/timezone');
10 // var featureToggles = require('../../web/middlewares/feature-toggles');
11 // var preventClickjackingMiddleware = require('../../web/middlewares/prevent-clickjacking');
12 // var preventClickjackingOnlyGitterEmbedMiddleware = require('../../web/middlewares/prevent-clickjacking-only-gitter-embed');
13 // var archive = require('./archive');
14 // var identifyRoute = require('gitter-web-env').middlewares.identifyRoute;
15 // var redirectErrorMiddleware = require('../uri-context/redirect-error-middleware');
16 // var desktopRenderer = require('../renderers/desktop-renderer');
17 // var embedRenderer = require('../renderers/embed-renderer');
18 const {
19 getCanonicalAliasForGitterRoomUri
20 } = require('gitter-web-matrix-bridge/lib/matrix-alias-utils');
22 // function saveRoom(req) {
23 // var userId = req.user && req.user.id;
24 // var troupeId = req.uriContext && req.uriContext.troupe && req.uriContext.troupe.id;
26 // if (userId && troupeId) {
27 // recentRoomService.saveLastVisitedTroupeforUserId(userId, troupeId);
28 // }
29 // }
31 // Redirect from
32 // `gitter.im/:roomPart1/:roomPart2[/:roomPart3]` -> `app.gitter.im/#/room/#roomPart1_roomPart2[_roomPart3]:gitter.im`
33 const redirectRoomToElementMiddlewarePipeline = [
34 uriContextResolverMiddleware,
35 (req, res) => {
36 var troupe = req.uriContext.troupe;
37 if (!troupe) {
38 return res.redirect(config.get('web:basepath'));
41 const matrixRoomAlias = getCanonicalAliasForGitterRoomUri(troupe.uri);
42 const elementUrl = config.get('element:appUrl');
43 res.redirect(elementUrl + `#/room/${matrixRoomAlias}`);
47 // var mainFrameMiddlewarePipeline = [
48 // identifyRoute('app-main-frame'),
49 // preventClickjackingMiddleware,
50 // featureToggles,
51 // uriContextResolverMiddleware,
52 // isPhoneMiddleware,
53 // timezoneMiddleware,
54 // function(req, res, next) {
55 // var uriContext = req.uriContext;
57 // return desktopRenderer.renderView(req, res, next, {
58 // uriContext: uriContext
59 // });
60 // },
61 // redirectErrorMiddleware
62 // ];
64 // var frameMiddlewarePipeline = [
65 // identifyRoute('app-chat-frame'), // Legacy name
66 // preventClickjackingOnlyGitterEmbedMiddleware,
67 // featureToggles,
68 // uriContextResolverMiddleware,
69 // isPhoneMiddleware,
70 // timezoneMiddleware,
71 // function(req, res, next) {
72 // saveRoom(req);
74 // return desktopRenderer.renderView(req, res, next, {
75 // uriContext: req.uriContext
76 // });
77 // },
78 // redirectErrorMiddleware
79 // ];
81 // var embedMiddlewarePipeline = [
82 // identifyRoute('app-embed-frame'),
83 // featureToggles,
84 // uriContextResolverMiddleware,
85 // isPhoneMiddleware,
86 // timezoneMiddleware,
87 // function(req, res, next) {
88 // return embedRenderer.renderSecondaryView(req, res, next, {
89 // uriContext: req.uriContext
90 // });
91 // },
92 // redirectErrorMiddleware
93 // ];
95 var router = express.Router({ caseSensitive: true, mergeParams: true });
97 ['/:roomPart1', '/:roomPart1/:roomPart2', '/:roomPart1/:roomPart2/:roomPart3'].forEach(function(
98 path
99 ) {
100 router.get(
101 path + '/archives',
102 //archive.linksList
103 redirectRoomToElementMiddlewarePipeline
105 router.get(
106 path + '/archives/all',
107 //archive.datesList
108 redirectRoomToElementMiddlewarePipeline
110 router.get(
111 path + '/archives/:yyyy(\\d{4})/:mm(\\d{2})/:dd(\\d{2})/:hourRange(\\d\\d?-\\d\\d?)?',
112 //archive.chatArchive
113 redirectRoomToElementMiddlewarePipeline
116 // Secondary view
117 //router.get(path + '/~(chat|iframe)', frameMiddlewarePipeline);
119 // Embedded View
120 //router.get(path + '/~embed', embedMiddlewarePipeline);
122 // Primary View
123 router.get(
124 path,
125 //mainFrameMiddlewarePipeline
126 redirectRoomToElementMiddlewarePipeline
130 module.exports = router;