badmfck-api-server 1.9.2 → 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/apiServer/APIService.d.ts +2 -1
- package/dist/apiServer/APIService.js +3 -1
- package/dist/apiServer/LogService.d.ts +1 -1
- package/dist/apiServer/LogService.js +4 -4
- package/dist/apiServer/WebsocketService.d.ts +4 -1
- package/dist/apiServer/WebsocketService.js +6 -1
- package/dist/apiServer/helper/UID.js +1 -1
- package/package.json +2 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Response } from 'express';
|
1
|
+
import { Application, Response } from 'express';
|
2
2
|
import { BaseService, IBaseService } from './BaseService';
|
3
3
|
import { IBaseEndpoint } from './BaseEndpoint';
|
4
4
|
import { HTTPRequestVO, TransferPacketVO } from './structures/Interfaces';
|
@@ -39,6 +39,7 @@ export declare function getDefaultOptions(): APIServiceOptions;
|
|
39
39
|
export declare const REQ_CREATE_NET_LOG: Req<void, APIServiceNetworkLogItem>;
|
40
40
|
export declare const REQ_HTTP_LOG: Req<void, APIServiceNetworkLogItem[]>;
|
41
41
|
export declare const REQ_HTTP_REQUESTS_COUNT: Req<void, number>;
|
42
|
+
export declare const REQ_HTTP_SERVER: Req<void, Application>;
|
42
43
|
export declare function Initializer(services: IBaseService[]): Promise<void>;
|
43
44
|
export declare class APIService extends BaseService {
|
44
45
|
private static nextLogID;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.APIService = exports.Initializer = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.REQ_CREATE_NET_LOG = exports.getDefaultOptions = void 0;
|
6
|
+
exports.APIService = exports.Initializer = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.REQ_CREATE_NET_LOG = exports.getDefaultOptions = void 0;
|
7
7
|
const express_1 = __importDefault(require("express"));
|
8
8
|
const BaseService_1 = require("./BaseService");
|
9
9
|
const cors_1 = __importDefault(require("cors"));
|
@@ -43,6 +43,7 @@ exports.getDefaultOptions = getDefaultOptions;
|
|
43
43
|
exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req(undefined, "REQ_CREATE_NET_LOG");
|
44
44
|
exports.REQ_HTTP_LOG = new badmfck_signal_1.Req(undefined, "REQ_HTTP_LOG");
|
45
45
|
exports.REQ_HTTP_REQUESTS_COUNT = new badmfck_signal_1.Req(undefined, "REQ_HTTP_REQUESTS_COUNT");
|
46
|
+
exports.REQ_HTTP_SERVER = new badmfck_signal_1.Req(undefined, "REQ_HTTP_SERVER");
|
46
47
|
const activeServices = [];
|
47
48
|
const entryPoints = [];
|
48
49
|
async function Initializer(services) {
|
@@ -102,6 +103,7 @@ class APIService extends BaseService_1.BaseService {
|
|
102
103
|
return log;
|
103
104
|
};
|
104
105
|
const app = (0, express_1.default)();
|
106
|
+
exports.REQ_HTTP_SERVER.listener = async (ignore) => app;
|
105
107
|
if (this.options.isProductionEnvironment)
|
106
108
|
app.set("env", 'production');
|
107
109
|
app.use(express_1.default.json({ limit: '10mb' }));
|
@@ -120,7 +120,7 @@ class LogService extends BaseService_1.BaseService {
|
|
120
120
|
return;
|
121
121
|
const msg = log.data[0];
|
122
122
|
const optional = log.data[1];
|
123
|
-
let text = this.createText(msg);
|
123
|
+
let text = this.createText(msg, log.level);
|
124
124
|
let source = "";
|
125
125
|
if (text.startsWith("${") && text.endsWith("}") && text.indexOf(".js") !== -1) {
|
126
126
|
source = text.substring(2, text.length - 1);
|
@@ -142,7 +142,7 @@ class LogService extends BaseService_1.BaseService {
|
|
142
142
|
showlog = true;
|
143
143
|
if (optional) {
|
144
144
|
for (let i of optional)
|
145
|
-
text += ", " + this.createText(i);
|
145
|
+
text += ", " + this.createText(i, this.level);
|
146
146
|
}
|
147
147
|
const d = new Date();
|
148
148
|
const logitem = {
|
@@ -180,7 +180,7 @@ class LogService extends BaseService_1.BaseService {
|
|
180
180
|
return "0" + num;
|
181
181
|
return num + "";
|
182
182
|
}
|
183
|
-
createText(data) {
|
183
|
+
createText(data, level) {
|
184
184
|
if (data === null)
|
185
185
|
return "null";
|
186
186
|
if (data === undefined)
|
@@ -210,7 +210,7 @@ class LogService extends BaseService_1.BaseService {
|
|
210
210
|
else {
|
211
211
|
res = data + "";
|
212
212
|
}
|
213
|
-
if (res.length > this.options.textLimit)
|
213
|
+
if (res.length > this.options.textLimit && level === LOG_LEVEL.INFO)
|
214
214
|
res = res.substring(0, this.options.textLimit) + "... (total: " + res.length + ")";
|
215
215
|
return res;
|
216
216
|
}
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import { BaseService } from "./BaseService";
|
2
|
+
export interface IWebSocketServiceOptions {
|
3
|
+
}
|
2
4
|
export declare class WebsocketService extends BaseService {
|
3
|
-
|
5
|
+
options: IWebSocketServiceOptions;
|
6
|
+
constructor(opt?: IWebSocketServiceOptions);
|
4
7
|
init(): Promise<void>;
|
5
8
|
}
|
@@ -2,9 +2,14 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.WebsocketService = void 0;
|
4
4
|
const BaseService_1 = require("./BaseService");
|
5
|
+
const getDefaultWebSocketServiceOptions = () => {
|
6
|
+
return {};
|
7
|
+
};
|
5
8
|
class WebsocketService extends BaseService_1.BaseService {
|
6
|
-
|
9
|
+
options;
|
10
|
+
constructor(opt) {
|
7
11
|
super("WebsocketService");
|
12
|
+
this.options = { ...getDefaultWebSocketServiceOptions(), opt };
|
8
13
|
}
|
9
14
|
async init() {
|
10
15
|
super.init();
|
@@ -15,7 +15,7 @@ class UID {
|
|
15
15
|
+ Math.round(Math.random() * 1000)).toString(16), 'hex').toString('base64');
|
16
16
|
uid = uid.replaceAll("=", "");
|
17
17
|
uid = uid.replaceAll("+", ".");
|
18
|
-
uid = uid.replaceAll("/", "
|
18
|
+
uid = uid.replaceAll("/", "_");
|
19
19
|
return uid;
|
20
20
|
}
|
21
21
|
static generateRandomNumberBase(count) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "badmfck-api-server",
|
3
|
-
"version": "1.9.
|
3
|
+
"version": "1.9.4",
|
4
4
|
"description": "Simple API http server based on express",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
"express": "^4.19.2",
|
27
27
|
"express-fileupload": "^1.5.0",
|
28
28
|
"mysql": "^2.18.1",
|
29
|
-
"ws": "^8.
|
29
|
+
"ws": "^8.18.0"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
32
|
"@types/cors": "^2.8.13",
|