Skip to content

Commit

Permalink
Add method to return non-proxied URLs
Browse files Browse the repository at this point in the history
Uses string interpolation to get around the proxy rewriting the URLs.
  • Loading branch information
thostetler committed Feb 2, 2021
1 parent a6bb21d commit 16a86bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/config/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')}`;
};
5 changes: 3 additions & 2 deletions src/js/apps/discovery/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<p>
You are using a proxied version of ADS, we recommend you switch to the regular non-proxied URL:
<a href="https://ui.adsabs.harvard.edu${location.pathname}" rel="noopener noreferrer">https://ui.adsabs.harvard.edu</a></p>
<a href="${url}${location.pathname}" rel="noopener noreferrer">${url}</a></p>
<p>
Configure authenticated access to publisher content via the Library Link Server in your account
<a href="https://ui.adsabs.harvard.edu/user/settings/librarylink" rel="noopener noreferrer">preferences</a>.
<a href="${url}/user/settings/librarylink" rel="noopener noreferrer">preferences</a>.
</p>
`;

Expand Down

0 comments on commit 16a86bc

Please sign in to comment.