Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / utils / check-already-on-unauthorized-url.js
blob08b561bd305078cef4f070d4d4a0c0e734c20e31
1 'use strict';
3 var escapeStringRegexp = require('escape-string-regexp');
4 var unauthorizedRedirectMap = require('./unauthorized-redirect-map');
6 var unauthorizedUrlRedirectRegexList = Object.keys(unauthorizedRedirectMap).map(redirectKey => {
7 const redirectUrl = unauthorizedRedirectMap[redirectKey];
8 return new RegExp(`${escapeStringRegexp(redirectUrl)}(\\/(\\?.*)?)?$`);
9 });
11 function checkAlreadyOnUnauthorizedUrl(url) {
12 // Avoid a redirect loop even when someone is forcing a token via
13 // `?access_token=xxxtoken` query parameter or `Authorization: bearer xxxtoken` header
14 return unauthorizedUrlRedirectRegexList.some(unauthorizedRe => {
15 return url.match(unauthorizedRe);
16 });
19 module.exports = checkAlreadyOnUnauthorizedUrl;