Skip to content

Commit

Permalink
Merge pull request #2717 from Expensify/marcaaron-fixProxyStaging
Browse files Browse the repository at this point in the history
Fix web proxy when accessing staging API
  • Loading branch information
NikkiWines authored May 6, 2021
2 parents 626cdf3 + 96edd84 commit 84ad169
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions web/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ if (process.env.USE_WEB_PROXY === 'false') {
process.exit();
}

let host = 'www.expensify.com';

// If we are testing against the staging API then we must use the correct host here or nothing with work.
if (/staging/.test(process.env.EXPENSIFY_URL_COM)) {
host = 'staging.expensify.com';
}

// eslint-disable-next-line no-console
console.log(`Creating proxy with host: ${host}`);

/**
* Local proxy server that hits the production endpoint
* to get around CORS issues. We use this so that it's
Expand All @@ -15,12 +25,12 @@ if (process.env.USE_WEB_PROXY === 'false') {
*/
const server = http.createServer((request, response) => {
const proxyRequest = https.request({
hostname: 'www.expensify.com',
hostname: host,
method: 'POST',
path: request.url,
headers: {
...request.headers,
host: 'www.expensify.com',
host,
},
port: 443,
});
Expand Down

0 comments on commit 84ad169

Please sign in to comment.