-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_client.js
More file actions
50 lines (40 loc) · 1021 Bytes
/
testing_client.js
File metadata and controls
50 lines (40 loc) · 1021 Bytes
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
39
40
41
42
43
44
45
46
47
'use strict';
const https = require('https');
const fs = require('fs');
const diff_match_patch = require('./diff_match_patch');
const diff = new diff_match_patch.diff_match_patch();
let cache;
function getDynamicFile() {
let options = {
host: 'localhost',
port: 8000,
path: '/dynamic.html'
};
if (cache !== undefined) {
options.headers = {
'Delta-Version': cache.version
}
}
let req = https.get(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
req.end();
//console.log(res.headers);
if (res.headers['delta-version'] !== undefined) {
if (res.headers['delta-patch'] === 'true') {
console.log(data);
data = diff.patch_apply(JSON.parse(data), cache.data)[0];
}
//console.log(data);
cache = {
version: res.headers['delta-version'],
data: data
};
}
});
});
}
setInterval(getDynamicFile, 3000);