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

Look at the platform to decide how to choose API #12880

Merged
merged 11 commits into from
Nov 24, 2022
7 changes: 4 additions & 3 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import CONFIG from '../CONFIG';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import HttpsError from './Errors/HttpsError';
import shouldUseStagingServer from './shouldUseStagingServer';

let shouldUseStagingServer = false;
let stagingServerToggleState = false;
Onyx.connect({
key: ONYXKEYS.USER,
callback: val => shouldUseStagingServer = lodashGet(val, 'shouldUseStagingServer', true),
callback: val => stagingServerToggleState = lodashGet(val, 'shouldUseStagingServer', true),
});

let shouldFailAllRequests = false;
Expand Down Expand Up @@ -98,7 +99,7 @@ function xhr(command, data, type = CONST.NETWORK.METHOD.POST, shouldUseSecure =

let apiRoot = shouldUseSecure ? CONFIG.EXPENSIFY.SECURE_EXPENSIFY_URL : CONFIG.EXPENSIFY.URL_API_ROOT;

if (CONFIG.IS_IN_STAGING && shouldUseStagingServer) {
if (shouldUseStagingServer(stagingServerToggleState)) {
apiRoot = shouldUseSecure ? CONFIG.EXPENSIFY.STAGING_SECURE_EXPENSIFY_URL : CONFIG.EXPENSIFY.STAGING_EXPENSIFY_URL;
}

Expand Down
13 changes: 13 additions & 0 deletions src/libs/shouldUseStagingServer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import CONFIG from '../../CONFIG';

/**
* Helper method used to decide which API endpoint to call
*
* @param {Boolean} stagingServerToggleState
* @returns {Boolean}
*/
function shouldUseStagingServer(stagingServerToggleState) {
return CONFIG.IS_IN_STAGING && stagingServerToggleState;
}

export default shouldUseStagingServer;
7 changes: 7 additions & 0 deletions src/libs/shouldUseStagingServer/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* @param {Boolean} stagingServerToggleState
* @returns {Boolean}
*/
export default function shouldUseStagingServer(stagingServerToggleState) {
mountiny marked this conversation as resolved.
Show resolved Hide resolved
return stagingServerToggleState;
}