badmfck-api-server 1.9.4 → 1.9.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,10 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { Application, Response } from 'express';
|
2
3
|
import { BaseService, IBaseService } from './BaseService';
|
3
4
|
import { IBaseEndpoint } from './BaseEndpoint';
|
4
5
|
import { HTTPRequestVO, TransferPacketVO } from './structures/Interfaces';
|
5
6
|
import { Req } from "badmfck-signal";
|
7
|
+
import http from 'http';
|
6
8
|
export interface APIServiceNetworkLogItem {
|
7
9
|
id: number;
|
8
10
|
created: number;
|
@@ -39,7 +41,10 @@ export declare function getDefaultOptions(): APIServiceOptions;
|
|
39
41
|
export declare const REQ_CREATE_NET_LOG: Req<void, APIServiceNetworkLogItem>;
|
40
42
|
export declare const REQ_HTTP_LOG: Req<void, APIServiceNetworkLogItem[]>;
|
41
43
|
export declare const REQ_HTTP_REQUESTS_COUNT: Req<void, number>;
|
42
|
-
export declare const REQ_HTTP_SERVER: Req<void,
|
44
|
+
export declare const REQ_HTTP_SERVER: Req<void, {
|
45
|
+
express: Application;
|
46
|
+
http: http.Server;
|
47
|
+
}>;
|
43
48
|
export declare function Initializer(services: IBaseService[]): Promise<void>;
|
44
49
|
export declare class APIService extends BaseService {
|
45
50
|
private static nextLogID;
|
@@ -49,6 +54,7 @@ export declare class APIService extends BaseService {
|
|
49
54
|
private monitorIndexFile?;
|
50
55
|
private started;
|
51
56
|
private requestsCount;
|
57
|
+
private server;
|
52
58
|
netLog: APIServiceNetworkLogItem[];
|
53
59
|
constructor(options?: APIServiceOptions | null);
|
54
60
|
init(): Promise<void>;
|
@@ -1,4 +1,27 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
27
|
};
|
@@ -8,7 +31,7 @@ const express_1 = __importDefault(require("express"));
|
|
8
31
|
const BaseService_1 = require("./BaseService");
|
9
32
|
const cors_1 = __importDefault(require("cors"));
|
10
33
|
const BaseEndpoint_1 = require("./BaseEndpoint");
|
11
|
-
const DefaultErrors_1 =
|
34
|
+
const DefaultErrors_1 = __importStar(require("./structures/DefaultErrors"));
|
12
35
|
const badmfck_signal_1 = require("badmfck-signal");
|
13
36
|
const LogService_1 = require("./LogService");
|
14
37
|
const Monitor_1 = require("./monitor/Monitor");
|
@@ -19,6 +42,7 @@ const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
19
42
|
const os_1 = __importDefault(require("os"));
|
20
43
|
const Liveness_1 = require("./routes/Liveness");
|
21
44
|
const Readiness_1 = require("./routes/Readiness");
|
45
|
+
const http_1 = __importDefault(require("http"));
|
22
46
|
function getDefaultOptions() {
|
23
47
|
return {
|
24
48
|
port: 8091,
|
@@ -58,12 +82,13 @@ async function Initializer(services) {
|
|
58
82
|
exports.Initializer = Initializer;
|
59
83
|
class APIService extends BaseService_1.BaseService {
|
60
84
|
static nextLogID = 0;
|
61
|
-
version = "1.
|
85
|
+
version = "1.9.6";
|
62
86
|
options;
|
63
87
|
monitor;
|
64
88
|
monitorIndexFile;
|
65
89
|
started = new Date();
|
66
90
|
requestsCount = 0;
|
91
|
+
server = http_1.default;
|
67
92
|
netLog = [];
|
68
93
|
constructor(options) {
|
69
94
|
super('HTTP Service');
|
@@ -103,7 +128,8 @@ class APIService extends BaseService_1.BaseService {
|
|
103
128
|
return log;
|
104
129
|
};
|
105
130
|
const app = (0, express_1.default)();
|
106
|
-
|
131
|
+
const server = http_1.default.createServer(app);
|
132
|
+
exports.REQ_HTTP_SERVER.listener = async (ignore) => { return { express: app, http: server }; };
|
107
133
|
if (this.options.isProductionEnvironment)
|
108
134
|
app.set("env", 'production');
|
109
135
|
app.use(express_1.default.json({ limit: '10mb' }));
|
@@ -286,7 +312,7 @@ class APIService extends BaseService_1.BaseService {
|
|
286
312
|
httpStatus: 404
|
287
313
|
}, tme, req.path);
|
288
314
|
});
|
289
|
-
|
315
|
+
server.listen(this.options.port, () => {
|
290
316
|
(0, LogService_1.logCrit)('${APIService.js}', 'API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
|
291
317
|
});
|
292
318
|
}
|
@@ -299,6 +325,8 @@ class APIService extends BaseService_1.BaseService {
|
|
299
325
|
(0, LogService_1.logError)("Postproducer error", e);
|
300
326
|
}
|
301
327
|
}
|
328
|
+
if (DefaultErrors_1.ErrorUtils.isError(data))
|
329
|
+
data = { error: data, data: null };
|
302
330
|
data.responseTime = (+new Date()) - requestTime;
|
303
331
|
data.core = this.version;
|
304
332
|
data.endpoint = endpoint ?? "no_endpoint";
|