badmfck-api-server 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,13 +5,18 @@ export interface IBaseEndpoint {
|
|
5
5
|
init: () => Promise<void>;
|
6
6
|
ignoreHttpLogging: boolean;
|
7
7
|
}
|
8
|
+
export interface IEndpointHandler {
|
9
|
+
endpoint: string;
|
10
|
+
handler: (req: HTTPRequestVO) => Promise<TransferPacketVO<any>>;
|
11
|
+
}
|
8
12
|
export declare class BaseEndpoint implements IBaseEndpoint {
|
9
13
|
ignoreHttpLogging: boolean;
|
10
14
|
private static entrypoint;
|
15
|
+
private endpointHandlers;
|
11
16
|
static setEntryPoint: (ep: string) => void;
|
12
17
|
static getEntryPoint: () => string;
|
13
18
|
endpoints: string[];
|
14
|
-
constructor(ep: string | string[]);
|
19
|
+
constructor(ep: string | string[] | IEndpointHandler[]);
|
15
20
|
init(): Promise<void>;
|
16
21
|
execute(req: HTTPRequestVO): Promise<TransferPacketVO<any>>;
|
17
22
|
}
|
@@ -8,6 +8,7 @@ const DefaultErrors_1 = __importDefault(require("./structures/DefaultErrors"));
|
|
8
8
|
class BaseEndpoint {
|
9
9
|
ignoreHttpLogging = false;
|
10
10
|
static entrypoint = "/";
|
11
|
+
endpointHandlers = [];
|
11
12
|
static setEntryPoint = (ep) => {
|
12
13
|
this.entrypoint = ep;
|
13
14
|
if (!this.entrypoint.endsWith("/")) {
|
@@ -25,9 +26,19 @@ class BaseEndpoint {
|
|
25
26
|
ep = [ep];
|
26
27
|
let eps = [];
|
27
28
|
for (let i of ep) {
|
28
|
-
if (i
|
29
|
-
|
30
|
-
|
29
|
+
if (typeof i === "object" && "endpoint" in i && "handler" in i) {
|
30
|
+
if (i.endpoint.startsWith("/"))
|
31
|
+
i.endpoint = i.endpoint.substring(1);
|
32
|
+
eps.push(i.endpoint);
|
33
|
+
this.endpointHandlers.push(i);
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
if (typeof i === "string") {
|
37
|
+
if (i.startsWith("/"))
|
38
|
+
i = i.substring(1);
|
39
|
+
eps.push(i);
|
40
|
+
continue;
|
41
|
+
}
|
31
42
|
}
|
32
43
|
this.endpoints = eps;
|
33
44
|
}
|
@@ -37,6 +48,12 @@ class BaseEndpoint {
|
|
37
48
|
}
|
38
49
|
;
|
39
50
|
async execute(req) {
|
51
|
+
if (this.endpointHandlers && this.endpointHandlers.length > 0) {
|
52
|
+
for (let i of this.endpointHandlers) {
|
53
|
+
if (BaseEndpoint.entrypoint + i.endpoint === req.endpoint)
|
54
|
+
return i.handler(req);
|
55
|
+
}
|
56
|
+
}
|
40
57
|
return {
|
41
58
|
error: DefaultErrors_1.default.NOT_IMPLEMENTED,
|
42
59
|
data: null
|