forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
38 lines (32 loc) · 932 Bytes
/
index.ts
File metadata and controls
38 lines (32 loc) · 932 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
import { SubmissionRequest } from '@exceptionless/core';
import { NodeSubmissionAdapter } from '@exceptionless/node';
import {
exit,
stdin,
stdout
} from 'process';
import { Writable } from 'stream';
import { StringDecoder } from 'string_decoder';
const decoder = new StringDecoder('utf8');
const strings: string[] = [];
const jsonStream = new Writable();
(jsonStream as any)._write = (chunk: Buffer | string, encoding: string, next: () => void) => {
strings.push(decoder.write(chunk as Buffer));
next();
};
jsonStream.on('finish', () => {
const json = strings.join('');
const request: SubmissionRequest = JSON.parse(json);
const adapter = new NodeSubmissionAdapter();
adapter.sendRequest(request, (status, message, data, headers) => {
const result = {
status,
message,
data,
headers
};
stdout.write(JSON.stringify(result));
exit(0);
});
});
stdin.pipe(jsonStream);