-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.ts
33 lines (26 loc) · 836 Bytes
/
connect.ts
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
import http from 'http';
import { handler } from './brokers/index';
import { TMessage } from './types';
import { errorSerializer, serializer } from './logger';
import config from './config.json';
const server = http.createServer((request, response) => {
let data = '';
if (request.method === "GET") {
data = 'GET RESPONSE';
} else if (request.method === "POST") {
let data = '';
request.on('data', (chunk: string) => {
data += chunk;
});
request.on('end', async () => {
try {
await handler(data);
} catch(error) {
console.error('ERROR OUT handler', serializer(error));
}
})
}
response.end(data);
});
console.log('🚀 Start listen server');
server.listen(config.sender.port, config.sender.host);