forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
37 lines (33 loc) · 1.06 KB
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const http = require('http');
const https = require('https');
/**
* Local proxy server that hits the production endpoint
* to get around CORS issues. We use this so that it's
* possible to work on the app within a limited development
* environment that has no local API.
*/
const server = http.createServer((request, response) => {
const proxyRequest = https.request({
hostname: 'www.expensify.com',
method: 'POST',
path: request.url,
headers: {
...request.headers,
host: 'www.expensify.com',
},
port: 443,
});
request.pipe(proxyRequest);
proxyRequest.on('response', (proxyResponse) => {
response.writeHead(proxyResponse.statusCode, proxyResponse.headers);
proxyResponse.pipe(response);
});
proxyRequest.on('error', (error) => {
/* eslint-disable-next-line no-console */
console.log(error);
});
});
server.listen(9000, () => {
/* eslint-disable-next-line no-console */
console.log('Proxy server listening at http://localhost:9000');
});