Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to staging endpoints by running setStagingEnabled(true) in c… #14

Merged
merged 1 commit into from Oct 29, 2020
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -69,6 +69,7 @@ const lookForAccessToken = async () => {
}

async function start() {
await setupEndpoints;
lookForAccessToken();

browser.webRequest.onBeforeSendHeaders.addListener(async (details) => {
@@ -1,4 +1,30 @@
let DEBUG = false;
let API_BASE_URL = DEBUG ? 'http://localhost:5000' : 'https://ghosterysearch.com';
let SERP_BASE_URL = DEBUG ? 'http://localhost' : 'https://ghosterysearch.com';
const STAGING_BASE_URL = 'https://staging.ghosterysearch.com';
const PROD_BASE_URL = 'https://ghosterysearch.com';
let API_BASE_URL = DEBUG ? 'http://localhost:5000' : PROD_BASE_URL;
let SERP_BASE_URL = DEBUG ? 'http://localhost' : PROD_BASE_URL;
let AUTH_BASE_URL = 'https://consumerapi.ghostery.com/api/v2';

const setupEndpoints = (async function() {
const USE_STAGING = (await browser.storage.local.get('USE_STAGING'))['USE_STAGING'];
if (USE_STAGING) {
AUTH_BASE_URL = AUTH_BASE_URL.replace('.ghostery.com', '.ghosterystage.com');
console.log(`USING_STAGING: AUTH_BASE_URL=${AUTH_BASE_URL}`)
// only switch to staging search if DEBUG is disabled
if (!DEBUG) {
API_BASE_URL = STAGING_BASE_URL;
SERP_BASE_URL = STAGING_BASE_URL;
console.log(`USING_STAGING: Redirecting ghosterysearch.com to staging.ghosterysearch.com`)
browser.webRequest.onBeforeRequest.addListener(async (details) => {
return {
redirectUrl: details.url.replace(PROD_BASE_URL, STAGING_BASE_URL),
}
}, { urls: [`${PROD_BASE_URL}/*`]}, ["blocking"]);
}
}
})();

window.setStagingEnabled = async (shouldUseStaging) => {
await browser.storage.local.set({ USE_STAGING: shouldUseStaging });
document.location.reload();
}
ProTip! Use n and p to navigate between commits in a pull request.