mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 22:29:01 +02:00
8ec2f1a896
Redirect handling after logging out GitOrigin-RevId: 01562dbe71ff4f3571fb0d433b96ccca34aad24e
33 lines
851 B
JavaScript
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
|