diff --git a/src/config/shim.js b/src/config/shim.js index 64b808e2b..407f51f5a 100644 --- a/src/config/shim.js +++ b/src/config/shim.js @@ -84,3 +84,29 @@ bodyEl.classList.add('is-proxied'); } })(); + +/** + * Use a list of canonical URLs that might be changed by a proxy server, detect any + * changes, and return the correct canonical URL. + */ +window.getCanonicalUrl = () => { + const canonicalUrlPattern = /^https:\/\/(ui|qa|dev|devui)\.adsabs\.harvard\.edu$/; + + // URLs that could be rewritten by the proxy server + const couldChangeUrls = [ + { env: 'ui', url: 'https://ui.adsabs.harvard.edu' }, + { env: 'qa', url: 'https://qa.adsabs.harvard.edu' }, + { env: 'dev', url: 'https://dev.adsabs.harvard.edu' }, + { env: 'devui', url: 'https://devui.adsabs.harvard.edu' }, + ]; + + const [changedUrl] = couldChangeUrls.filter( + ({ url }) => !canonicalUrlPattern.test(url) + ); + + // if we detect a change in one of the URLs, return an interpolated string to keep from getting rewritten + if (typeof changedUrl !== 'undefined') { + return `https://${[changedUrl.env, 'adsabs', 'harvard', 'edu'].join('.')}`; + } + return `https://${['ui', 'adsabs', 'harvard', 'edu'].join('.')}`; +}; diff --git a/src/js/apps/discovery/main.js b/src/js/apps/discovery/main.js index 12fb401f3..18204b315 100644 --- a/src/js/apps/discovery/main.js +++ b/src/js/apps/discovery/main.js @@ -170,13 +170,14 @@ define(['config/discovery.config', 'module'], function(config, module) { // check for is-proxied class, and if present, send alert if ($('body').hasClass('is-proxied')) { + const url = window.getCanonicalUrl(); const msg = `

You are using a proxied version of ADS, we recommend you switch to the regular non-proxied URL: - https://ui.adsabs.harvard.edu

+ ${url}

Configure authenticated access to publisher content via the Library Link Server in your account - preferences. + preferences.

`;