Files
overleaf-cep/services/web/app/src/Features/Helpers/UrlHelper.js
T
Simon Detheridge 8ec2f1a896 Merge pull request #2157 from overleaf/jel-saml-logout-redirect
Redirect handling after logging out

GitOrigin-RevId: 01562dbe71ff4f3571fb0d433b96ccca34aad24e
2019-09-25 14:48:19 +00:00

33 lines
851 B
JavaScript

const Settings = require('settings-sharelatex')
const { URL } = require('url')
function getSafeRedirectPath(value) {
const baseURL = Settings.siteUrl // base URL is required to construct URL from path
const url = new URL(value, baseURL)
let safePath = `${url.pathname}${url.search}${url.hash}`
if (safePath === '/') {
safePath = undefined
}
return safePath
}
const UrlHelper = {
getSafeRedirectPath,
wrapUrlWithProxy(url) {
// TODO: Consider what to do for Community and Enterprise edition?
if (!Settings.apis.linkedUrlProxy.url) {
throw new Error('no linked url proxy configured')
}
return `${Settings.apis.linkedUrlProxy.url}?url=${encodeURIComponent(url)}`
},
prependHttpIfNeeded(url) {
if (!url.match('://')) {
url = `http://${url}`
}
return url
}
}
module.exports = UrlHelper