-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (62 loc) · 1.99 KB
/
index.js
File metadata and controls
74 lines (62 loc) · 1.99 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const http = require('http');
const url = require('url');
const { parse } = require('querystring');
const { libNode } = require('@tonclient/lib-node')
const { TonClient } = require('@tonclient/core')
// Keys displayed by DeBot
const CLIENT_KEYS = {
pub: '***',
sec: '***',
}
const port = 8181
const parameterNamePost = 'param'
var fs = require('fs');
TonClient.useBinaryLibrary(libNode)
const client = TonClient.default
//
// The server's public key. WILL NOT be changed.
//
const SERVICE_KEYS = { pub: 'a36bf515ee8de6b79d30b294bbe7162f5e2a45b95ea97e4baebab8873492ee43' }
const main = async (KAFKA_MESSAGE) => {
// Parse the message
const [idempKey, nonceBase64, encrypted] = KAFKA_MESSAGE.split(' ')
const { decrypted } = await client.crypto.nacl_box_open({
encrypted,
nonce: Buffer.from(nonceBase64, 'base64').toString('hex'),
their_public: SERVICE_KEYS.pub,
secret: CLIENT_KEYS.sec,
})
const base64ToUtf8 = (b) => Buffer.from(b, 'base64').toString('utf8')
console.log(base64ToUtf8(decrypted))
// process.exit(0)
}
var index = fs.readFileSync('robots.txt');
const requestListener = function (req, res) {
if (req.url === '/help' && req.method === 'GET') {
res.end('Welcome');
}
else if (req.url === '/robots.txt' && req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(index);
}
else if (req.method === 'GET') {
let urlRequest = url.parse(req.url, true);
res.end('ok');
}
else {
// POST and etc
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
let params = parse(body);
// console.log(params[parameterNamePost]);
main(params[parameterNamePost]).catch(console.log)
res.end('ok');
});
}
}
const server = http.createServer(requestListener);
server.listen(port);
console.log("http://127.0.0.1:8181/")