badmfck-api-server 1.9.3 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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;
@@ -1,14 +1,37 @@
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
  };
5
28
  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;
29
+ 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
30
  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 = __importDefault(require("./structures/DefaultErrors"));
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");
@@ -43,6 +66,7 @@ exports.getDefaultOptions = getDefaultOptions;
43
66
  exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req(undefined, "REQ_CREATE_NET_LOG");
44
67
  exports.REQ_HTTP_LOG = new badmfck_signal_1.Req(undefined, "REQ_HTTP_LOG");
45
68
  exports.REQ_HTTP_REQUESTS_COUNT = new badmfck_signal_1.Req(undefined, "REQ_HTTP_REQUESTS_COUNT");
69
+ exports.REQ_HTTP_SERVER = new badmfck_signal_1.Req(undefined, "REQ_HTTP_SERVER");
46
70
  const activeServices = [];
47
71
  const entryPoints = [];
48
72
  async function Initializer(services) {
@@ -102,6 +126,7 @@ class APIService extends BaseService_1.BaseService {
102
126
  return log;
103
127
  };
104
128
  const app = (0, express_1.default)();
129
+ exports.REQ_HTTP_SERVER.listener = async (ignore) => app;
105
130
  if (this.options.isProductionEnvironment)
106
131
  app.set("env", 'production');
107
132
  app.use(express_1.default.json({ limit: '10mb' }));
@@ -297,6 +322,8 @@ class APIService extends BaseService_1.BaseService {
297
322
  (0, LogService_1.logError)("Postproducer error", e);
298
323
  }
299
324
  }
325
+ if (DefaultErrors_1.ErrorUtils.isError(data))
326
+ data = { error: data, data: null };
300
327
  data.responseTime = (+new Date()) - requestTime;
301
328
  data.core = this.version;
302
329
  data.endpoint = endpoint ?? "no_endpoint";
@@ -1,5 +1,8 @@
1
1
  import { BaseService } from "./BaseService";
2
+ export interface IWebSocketServiceOptions {
3
+ }
2
4
  export declare class WebsocketService extends BaseService {
3
- constructor();
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
- constructor() {
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",
3
+ "version": "1.9.5",
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.17.0"
29
+ "ws": "^8.18.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/cors": "^2.8.13",