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');
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);
32 // `gitter.im/:roomPart1/:roomPart2[/:roomPart3]` -> `app.gitter.im/#/room/#roomPart1_roomPart2[_roomPart3]:gitter.im`
33 const redirectRoomToElementMiddlewarePipeline
= [
34 uriContextResolverMiddleware
,
36 var troupe
= req
.uriContext
.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,
51 // uriContextResolverMiddleware,
53 // timezoneMiddleware,
54 // function(req, res, next) {
55 // var uriContext = req.uriContext;
57 // return desktopRenderer.renderView(req, res, next, {
58 // uriContext: uriContext
61 // redirectErrorMiddleware
64 // var frameMiddlewarePipeline = [
65 // identifyRoute('app-chat-frame'), // Legacy name
66 // preventClickjackingOnlyGitterEmbedMiddleware,
68 // uriContextResolverMiddleware,
70 // timezoneMiddleware,
71 // function(req, res, next) {
74 // return desktopRenderer.renderView(req, res, next, {
75 // uriContext: req.uriContext
78 // redirectErrorMiddleware
81 // var embedMiddlewarePipeline = [
82 // identifyRoute('app-embed-frame'),
84 // uriContextResolverMiddleware,
86 // timezoneMiddleware,
87 // function(req, res, next) {
88 // return embedRenderer.renderSecondaryView(req, res, next, {
89 // uriContext: req.uriContext
92 // redirectErrorMiddleware
95 var router
= express
.Router({ caseSensitive
: true, mergeParams
: true });
97 ['/:roomPart1', '/:roomPart1/:roomPart2', '/:roomPart1/:roomPart2/:roomPart3'].forEach(function(
103 redirectRoomToElementMiddlewarePipeline
106 path
+ '/archives/all',
108 redirectRoomToElementMiddlewarePipeline
111 path
+ '/archives/:yyyy(\\d{4})/:mm(\\d{2})/:dd(\\d{2})/:hourRange(\\d\\d?-\\d\\d?)?',
112 //archive.chatArchive
113 redirectRoomToElementMiddlewarePipeline
117 //router.get(path + '/~(chat|iframe)', frameMiddlewarePipeline);
120 //router.get(path + '/~embed', embedMiddlewarePipeline);
125 //mainFrameMiddlewarePipeline
126 redirectRoomToElementMiddlewarePipeline
130 module
.exports
= router
;