-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (32 loc) · 813 Bytes
/
server.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
var https = require('https');
var http = require('http');
var server = http.createServer((request, response) => {
var body = '';
request.on('data', (chunk) => {
body += chunk;
console.log('chunk recieved');
});
request.on('end', () => {
console.log('request ended');
try {
var options = JSON.parse(body);
var httpsResult = '';
var httpsRequest = https.request(options, (httpsResponse) => {
httpsResponse.on('data', (data) => {
httpsResult += data;
console.log('https chunk recieved');
});
httpsResponse.on('end', () => {
response.end(httpsResult);
console.log('https response ended');
});
});
httpsRequest.end();
} catch (error) {
console.log(error);
response.end(error);
}
});
});
server.listen('4200');
console.log('start listening');