forked from cryptpad/cryptpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-accounts.js
40 lines (37 loc) · 1000 Bytes
/
check-accounts.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
39
40
/* globals Buffer */
var Https = require('https');
var Config = require("./config.js");
var Package = require("./package.json");
var body = JSON.stringify({
domain: Config.myDomain,
adminEmail: Config.adminEmail,
version: Package.version,
});
var options = {
host: 'accounts.cryptpad.fr',
path: '/api/getauthorized',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body)
}
};
Https.request(options, function (response) {
if (!('' + response.statusCode).match(/^2\d\d$/)) {
throw new Error('SERVER ERROR ' + response.statusCode);
}
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
try {
var json = JSON.parse(str);
console.log(json);
} catch (e) {
throw new Error(e);
}
});
}).on('error', function (e) {
console.error(e);
}).end(body);