-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.js
29 lines (25 loc) · 849 Bytes
/
node.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
import CryptonAPI from './core.js';
import { request } from 'https';
import { Buffer } from 'buffer';
let cookies = '';
function transport(method, url, body){
return new Promise((resolve, reject) => {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
if(cookies) headers.Cookie = cookies;
const req = request(url, { method, headers }, res => {
const data = [];
res.on('data', chunk => data.push(chunk));
res.on('error', reject);
res.on('end', () => resolve(Buffer.concat(data).toString('utf8')));
});
req.on('error', reject);
req.write(body);
req.end();
});
}
function saveToken(token){
cookies = `auth_token=${token}`;
}
export default new CryptonAPI(transport, saveToken);