-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (35 loc) · 856 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
35
36
37
38
const http2 = require('http2');
const fs = require('fs');
const util = require('util')
const server = http2.createSecureServer({
key: fs.readFileSync('k.pem'),
cert: fs.readFileSync('c.pem')
});
server.on('error', (err) => console.error(err));
server.on('stream', (stream, headers) => {
// stream is a Duplex
// stream.respond({
// 'content-type': 'text/html',
// ':status': 200
// });
let body = ''
stream.on('data' , (chunk)=>{
console.log(`chunk ===> ${JSON.stringify(chunk)}`)
body+=chunk;
});
stream.on('end' , (chunk)=>{
if (chunk)
body+=chunk;
stream.respond({
'content-type': 'text/html',
':status': 200
});
const result = JSON.stringify({
headers,
body
},null, 2);
console.log(`result ===> ${result}`)
stream.end(result);
})
});
server.listen(8443);