badmfck-api-server 1.4.7 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ async function Initializer(services) {
|
|
43
43
|
exports.Initializer = Initializer;
|
44
44
|
class APIService extends BaseService_1.BaseService {
|
45
45
|
static nextLogID = 0;
|
46
|
-
version = "1.
|
46
|
+
version = "1.5.0";
|
47
47
|
options;
|
48
48
|
netLog = [];
|
49
49
|
constructor(options) {
|
@@ -151,6 +151,7 @@ class APIService extends BaseService_1.BaseService {
|
|
151
151
|
result = await i.execute(httpRequest);
|
152
152
|
}
|
153
153
|
catch (e) {
|
154
|
+
console.error(e);
|
154
155
|
if (this.options.onError)
|
155
156
|
this.options.onError(e);
|
156
157
|
this.sendResponse(res, {
|
@@ -158,6 +159,7 @@ class APIService extends BaseService_1.BaseService {
|
|
158
159
|
error: {
|
159
160
|
code: 10002,
|
160
161
|
message: "Internal server error",
|
162
|
+
details: `${e}`
|
161
163
|
}
|
162
164
|
}, tme, ep, log);
|
163
165
|
return;
|
@@ -31,6 +31,13 @@ class BaseEndpoint {
|
|
31
31
|
}
|
32
32
|
registerEndpoints(endpoints) {
|
33
33
|
for (let i of endpoints) {
|
34
|
+
if (i.endpoint === "" || i.endpoint === "/") {
|
35
|
+
let empty = i.endpoint === "";
|
36
|
+
i.endpoint = this.endpoint;
|
37
|
+
if (i.endpoint.endsWith("/") && empty)
|
38
|
+
i.endpoint = i.endpoint.substring(0, i.endpoint.length - 1);
|
39
|
+
continue;
|
40
|
+
}
|
34
41
|
if (i.endpoint.startsWith("/"))
|
35
42
|
i.endpoint = i.endpoint.substring(1);
|
36
43
|
if (i.endpoint.endsWith("/"))
|
@@ -53,7 +60,7 @@ class BaseEndpoint {
|
|
53
60
|
if (this.endpoints && this.endpoints.length > 0) {
|
54
61
|
for (let i of this.endpoints) {
|
55
62
|
if (BaseEndpoint.entrypoint + i.endpoint === req.endpoint && i.handler && typeof i.handler === "function")
|
56
|
-
return i.handler(req);
|
63
|
+
return i.handler.call(this, req);
|
57
64
|
}
|
58
65
|
}
|
59
66
|
(0, LogService_1.logWarn)("${BaseEndpoint.js}", "Unhandled entrypoint: " + this.endpoint);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WebsocketService = void 0;
|
4
|
+
const BaseService_1 = require("./BaseService");
|
5
|
+
class WebsocketService extends BaseService_1.BaseService {
|
6
|
+
constructor() {
|
7
|
+
super("WebsocketService");
|
8
|
+
}
|
9
|
+
async init() {
|
10
|
+
super.init();
|
11
|
+
}
|
12
|
+
}
|
13
|
+
exports.WebsocketService = WebsocketService;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "badmfck-api-server",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.0",
|
4
4
|
"description": "Simple API http server based on express",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -19,11 +19,13 @@
|
|
19
19
|
],
|
20
20
|
"dependencies": {
|
21
21
|
"@types/mysql": "^2.15.21",
|
22
|
+
"@types/ws": "^8.5.9",
|
22
23
|
"axios": "^1.4.0",
|
23
24
|
"badmfck-signal": "^1.2.7",
|
24
25
|
"cors": "^2.8.5",
|
25
26
|
"express": "^4.18.2",
|
26
|
-
"mysql": "^2.18.1"
|
27
|
+
"mysql": "^2.18.1",
|
28
|
+
"ws": "^8.14.2"
|
27
29
|
},
|
28
30
|
"devDependencies": {
|
29
31
|
"@types/cors": "^2.8.13",
|