Skip to content

Commit

Permalink
Add proxy warning alert
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Jan 29, 2021
1 parent 859c6eb commit 82f642b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/config/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,17 @@
})();
}
})();

/**
* In the case of a proxied URL, we want to show a warning message
* Do that by checking for the presence of the canonical URL ([ui|dev|qa].adsabs.harvard.edu)
*/
(function checkIfProxied() {
const canonicalUrlPattern = /^(ui|qa|dev)\.adsabs\.harvard\.edu$/;

// if test fails, it is proxied url, set a class on body element
if (!canonicalUrlPattern.test(location.hostname)) {
const [bodyEl] = document.getElementsByTagName('body');
bodyEl.classList.add('is-proxied');
}
})();
26 changes: 24 additions & 2 deletions src/js/apps/discovery/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ define(['config/discovery.config', 'module'], function(config, module) {
'js/components/application',
'js/mixins/discovery_bootstrap',
'js/mixins/api_access',
'js/components/api_feedback',
'analytics',
], function(Router, Application, DiscoveryBootstrap, ApiAccess, analytics) {
], function(
Router,
Application,
DiscoveryBootstrap,
ApiAccess,
ApiFeedback,
analytics
) {
var updateProgress =
typeof window.__setAppLoadingProgress === 'function'
? window.__setAppLoadingProgress
Expand Down Expand Up @@ -156,10 +164,24 @@ define(['config/discovery.config', 'module'], function(config, module) {

// accessibility: skip to main content
$('body').on('click', '#skip-to-main-content', function() {
$('#main-content').focus();
$('#main-content').trigger('focus');
return false;
});

// check for is-proxied class, and if present, send alert
if ($('body').hasClass('is-proxied')) {
const msg = `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>`;

pubsub.publish(
pubsub.getCurrentPubSubKey(),
pubsub.ALERT,
new ApiFeedback({
type: 'danger',
msg,
})
);
}

// app is loaded, send timing event

if (window.__PAGE_LOAD_TIMESTAMP) {
Expand Down

0 comments on commit 82f642b

Please sign in to comment.