chyz 2.0.1-rc.36 → 2.0.1-rc.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseChyz.d.ts +74 -0
- package/dist/BaseChyz.d.ts.map +1 -0
- package/dist/BaseChyz.js +586 -0
- package/dist/base/ActionFilter.d.ts +32 -0
- package/dist/base/ActionFilter.d.ts.map +1 -0
- package/dist/base/ActionFilter.js +90 -0
- package/dist/base/BadRequestHttpException.d.ts +6 -0
- package/dist/base/BadRequestHttpException.d.ts.map +1 -0
- package/dist/base/BadRequestHttpException.js +17 -0
- package/dist/base/BaseError.d.ts +44 -0
- package/dist/base/BaseError.d.ts.map +1 -0
- package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
- package/dist/base/Behavior.d.ts +4 -0
- package/dist/base/Behavior.d.ts.map +1 -0
- package/dist/base/Behavior.js +7 -0
- package/dist/base/CBaseObject.d.ts +5 -0
- package/dist/base/CBaseObject.d.ts.map +1 -0
- package/dist/base/CBaseObject.js +16 -0
- package/dist/base/CEvents.d.ts +13 -0
- package/dist/base/CEvents.d.ts.map +1 -0
- package/dist/base/CEvents.js +24 -0
- package/dist/base/CRequest.d.ts +2 -0
- package/dist/base/CRequest.d.ts.map +1 -0
- package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
- package/dist/base/CWebController.d.ts +44 -0
- package/dist/base/CWebController.d.ts.map +1 -0
- package/dist/base/CWebController.js +81 -0
- package/dist/base/Component.d.ts +21 -0
- package/dist/base/Component.d.ts.map +1 -0
- package/dist/base/Component.js +57 -0
- package/dist/base/Configurable.d.ts +3 -0
- package/dist/base/Configurable.d.ts.map +1 -0
- package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
- package/dist/base/DataErrorDbException.d.ts +6 -0
- package/dist/base/DataErrorDbException.d.ts.map +1 -0
- package/dist/base/DataErrorDbException.js +17 -0
- package/dist/base/DbConnection.d.ts +13 -0
- package/dist/base/DbConnection.d.ts.map +1 -0
- package/dist/base/DbConnection.js +53 -0
- package/dist/base/ForbiddenHttpException.d.ts +5 -0
- package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
- package/dist/base/ForbiddenHttpException.js +16 -0
- package/dist/base/InvalidArgumentException.d.ts +6 -0
- package/dist/base/InvalidArgumentException.d.ts.map +1 -0
- package/dist/base/InvalidArgumentException.js +17 -0
- package/dist/base/InvalidConfigException.d.ts +6 -0
- package/dist/base/InvalidConfigException.d.ts.map +1 -0
- package/dist/base/InvalidConfigException.js +17 -0
- package/dist/base/Logs.d.ts +22 -0
- package/dist/base/Logs.d.ts.map +1 -0
- package/{base/Logs.ts → dist/base/Logs.js} +24 -41
- package/dist/base/Model.d.ts +302 -0
- package/dist/base/Model.d.ts.map +1 -0
- package/{base/Model.ts → dist/base/Model.js} +158 -225
- package/dist/base/ModelManager.d.ts +2 -0
- package/dist/base/ModelManager.d.ts.map +1 -0
- package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
- package/dist/base/NotFoundHttpException.d.ts +6 -0
- package/dist/base/NotFoundHttpException.d.ts.map +1 -0
- package/dist/base/NotFoundHttpException.js +17 -0
- package/dist/base/RestClient.d.ts +7 -0
- package/dist/base/RestClient.d.ts.map +1 -0
- package/dist/base/RestClient.js +25 -0
- package/dist/base/UnauthorizedHttpException.d.ts +6 -0
- package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +17 -0
- package/dist/base/ValidationHttpException.d.ts +6 -0
- package/dist/base/ValidationHttpException.d.ts.map +1 -0
- package/dist/base/ValidationHttpException.js +17 -0
- package/dist/base/db/Exception.d.ts +7 -0
- package/dist/base/db/Exception.d.ts.map +1 -0
- package/dist/base/db/Exception.js +15 -0
- package/dist/base/index.d.ts +20 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +41 -0
- package/dist/decorator/Middleware.d.ts +4 -0
- package/dist/decorator/Middleware.d.ts.map +1 -0
- package/dist/decorator/Middleware.js +10 -0
- package/dist/decorator/controller.d.ts +3 -0
- package/dist/decorator/controller.d.ts.map +1 -0
- package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
- package/dist/decorator/delete.d.ts +3 -0
- package/dist/decorator/delete.d.ts.map +1 -0
- package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
- package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
- package/dist/decorator/get.d.ts +3 -0
- package/dist/decorator/get.d.ts.map +1 -0
- package/{decorator/get.ts → dist/decorator/get.js} +10 -11
- package/dist/decorator/index.d.ts +6 -0
- package/dist/decorator/index.d.ts.map +1 -0
- package/dist/decorator/index.js +13 -0
- package/dist/decorator/post.d.ts +3 -0
- package/dist/decorator/post.d.ts.map +1 -0
- package/{decorator/post.ts → dist/decorator/post.js} +10 -10
- package/dist/decorator/put.d.ts +3 -0
- package/dist/decorator/put.d.ts.map +1 -0
- package/{decorator/put.ts → dist/decorator/put.js} +9 -9
- package/dist/filters/AccessControl.d.ts +12 -0
- package/dist/filters/AccessControl.d.ts.map +1 -0
- package/dist/filters/AccessControl.js +83 -0
- package/dist/filters/AccessRule.d.ts +83 -0
- package/dist/filters/AccessRule.d.ts.map +1 -0
- package/dist/filters/AccessRule.js +136 -0
- package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
- package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
- package/dist/filters/auth/AuthInterface.js +2 -0
- package/dist/filters/auth/AuthMethod.d.ts +38 -0
- package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
- package/dist/filters/auth/AuthMethod.js +82 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBasicAuth.js +79 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBearerAuth.js +33 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpHeaderAuth.js +64 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
- package/dist/filters/auth/index.d.ts +5 -0
- package/dist/filters/auth/index.d.ts.map +1 -0
- package/dist/filters/auth/index.js +11 -0
- package/dist/filters/index.d.ts +3 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +7 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/log/log/config/log4js.json +55 -0
- package/dist/model/RouteDefinition.d.ts +7 -0
- package/dist/model/RouteDefinition.d.ts.map +1 -0
- package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
- package/dist/package.json +63 -0
- package/dist/rbac/AuthAssignment.d.ts +19 -0
- package/dist/rbac/AuthAssignment.d.ts.map +1 -0
- package/dist/rbac/AuthAssignment.js +44 -0
- package/dist/rbac/AuthItem.d.ts +27 -0
- package/dist/rbac/AuthItem.d.ts.map +1 -0
- package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
- package/dist/rbac/AuthItemChild.d.ts +19 -0
- package/dist/rbac/AuthItemChild.d.ts.map +1 -0
- package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
- package/dist/rbac/AuthManager.d.ts +112 -0
- package/dist/rbac/AuthManager.d.ts.map +1 -0
- package/dist/rbac/AuthManager.js +356 -0
- package/dist/rbac/index.d.ts +5 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/index.js +28 -0
- package/dist/requiments/Glob.d.ts +3 -0
- package/dist/requiments/Glob.d.ts.map +1 -0
- package/dist/requiments/Glob.js +10 -0
- package/dist/requiments/ReflectUtil.d.ts +1 -0
- package/dist/requiments/ReflectUtil.d.ts.map +1 -0
- package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
- package/dist/requiments/Utils.d.ts +2 -0
- package/dist/requiments/Utils.d.ts.map +1 -0
- package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
- package/dist/validators/BooleanValidator.d.ts +1 -0
- package/dist/validators/BooleanValidator.d.ts.map +1 -0
- package/dist/validators/BooleanValidator.js +1 -0
- package/dist/validators/CompareValidator.d.ts +1 -0
- package/dist/validators/CompareValidator.d.ts.map +1 -0
- package/dist/validators/CompareValidator.js +1 -0
- package/dist/validators/DateValidator.d.ts +1 -0
- package/dist/validators/DateValidator.d.ts.map +1 -0
- package/dist/validators/DateValidator.js +1 -0
- package/dist/validators/EmailValidator.d.ts +1 -0
- package/dist/validators/EmailValidator.d.ts.map +1 -0
- package/dist/validators/EmailValidator.js +1 -0
- package/dist/validators/Validator.d.ts +18 -0
- package/dist/validators/Validator.d.ts.map +1 -0
- package/dist/validators/Validator.js +27 -0
- package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
- package/dist/web/IdentityInterface.d.ts.map +1 -0
- package/dist/web/IdentityInterface.js +8 -0
- package/dist/web/WebUser.d.ts +72 -0
- package/dist/web/WebUser.d.ts.map +1 -0
- package/dist/web/WebUser.js +165 -0
- package/package.json +16 -56
- package/BaseChyz.ts +0 -623
- package/base/ActionFilter.ts +0 -88
- package/base/BadRequestHttpException.ts +0 -14
- package/base/Behavior.ts +0 -6
- package/base/CBaseObject.ts +0 -17
- package/base/CEvents.ts +0 -24
- package/base/CWebController.ts +0 -90
- package/base/Component.ts +0 -66
- package/base/DataErrorDbException.ts +0 -16
- package/base/DbConnection.ts +0 -55
- package/base/ForbiddenHttpException.ts +0 -15
- package/base/InvalidArgumentException.ts +0 -16
- package/base/InvalidConfigException.ts +0 -16
- package/base/NotFoundHttpException.ts +0 -14
- package/base/RestClient.ts +0 -26
- package/base/UnauthorizedHttpException.ts +0 -17
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -19
- package/decorator/Middleware.ts +0 -9
- package/decorator/enums/ControllerDecoratorParams.ts +0 -5
- package/decorator/index.ts +0 -5
- package/filters/AccessControl.ts +0 -74
- package/filters/AccessRule.ts +0 -182
- package/filters/auth/AuthMethod.ts +0 -100
- package/filters/auth/HttpBasicAuth.ts +0 -79
- package/filters/auth/HttpBearerAuth.ts +0 -34
- package/filters/auth/HttpHeaderAuth.ts +0 -61
- package/filters/auth/JwtHttpBearerAuth.ts +0 -83
- package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
- package/filters/auth/index.ts +0 -4
- package/filters/index.ts +0 -2
- package/index.ts +0 -80
- package/model/RouteDefinition.ts +0 -18
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthManager.ts +0 -399
- package/rbac/index.ts +0 -12
- package/validators/BooleanValidator.ts +0 -0
- package/validators/CompareValidator.ts +0 -0
- package/validators/DateValidator.ts +0 -0
- package/validators/EmailValidator.ts +0 -0
- package/validators/Validator.ts +0 -27
- package/web/WebUser.ts +0 -187
- /package/{README.md → dist/README.md} +0 -0
- /package/{log → dist/log}/config/log4js.json +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https server
|
|
3
|
+
*/
|
|
4
|
+
import { NextFunction, Request, Response } from "express";
|
|
5
|
+
/**
|
|
6
|
+
* Freamwork
|
|
7
|
+
*/
|
|
8
|
+
import { CWebController, Logs } from "./base";
|
|
9
|
+
import { RouteDefinition } from "./model/RouteDefinition";
|
|
10
|
+
export default class BaseChyz {
|
|
11
|
+
private config;
|
|
12
|
+
static httpServer: any;
|
|
13
|
+
static propvider: any;
|
|
14
|
+
private _port;
|
|
15
|
+
static db: any;
|
|
16
|
+
static date: any;
|
|
17
|
+
static routes: any;
|
|
18
|
+
static logs: Logs;
|
|
19
|
+
private static _validate;
|
|
20
|
+
private _controllerpath;
|
|
21
|
+
private static controllers;
|
|
22
|
+
static components: any;
|
|
23
|
+
static middlewares: any;
|
|
24
|
+
private static _EventEmitter;
|
|
25
|
+
static get EventEmitter(): any;
|
|
26
|
+
static set EventEmitter(value: any);
|
|
27
|
+
get controllerpath(): string;
|
|
28
|
+
set controllerpath(value: string);
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
init(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Listen port number
|
|
35
|
+
* Server port number get
|
|
36
|
+
*/
|
|
37
|
+
get port(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Listen port number
|
|
40
|
+
* Server port number setting
|
|
41
|
+
* @param value
|
|
42
|
+
*/
|
|
43
|
+
set port(value: number);
|
|
44
|
+
static get validate(): any;
|
|
45
|
+
static set validate(value: any);
|
|
46
|
+
app(config?: any): Promise<BaseChyz>;
|
|
47
|
+
static trace(...args: any[]): void;
|
|
48
|
+
static debug(...args: any[]): void;
|
|
49
|
+
static info(...args: any[]): void;
|
|
50
|
+
static warn(...args: any[]): void;
|
|
51
|
+
static error(...args: any[]): void;
|
|
52
|
+
static fatal(...args: any[]): void;
|
|
53
|
+
static warning(...args: any[]): void;
|
|
54
|
+
static t(text: string, params?: any): string | undefined;
|
|
55
|
+
errorLogger(error: any, req: any, res: any, next: any): void;
|
|
56
|
+
errorResponder(error: any, req: any, res: any, next: any): void;
|
|
57
|
+
errorHandler(err: any, req: any, res: any, next: any): any;
|
|
58
|
+
static getComponent(key: any): any;
|
|
59
|
+
static getMiddlewares(key: any): any;
|
|
60
|
+
/**
|
|
61
|
+
* load model
|
|
62
|
+
*/
|
|
63
|
+
loadModels(): void;
|
|
64
|
+
beforeMiddleware(req: Request, res: Response, next: NextFunction, instance: CWebController, route: RouteDefinition): Promise<void>;
|
|
65
|
+
responseHandler(req: Request, res: Response, next: NextFunction, instance: CWebController, route: RouteDefinition): Promise<void>;
|
|
66
|
+
afterMiddleware(req: Request, res: Response, next: NextFunction, instance: CWebController, route: RouteDefinition): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* load contoller
|
|
69
|
+
*/
|
|
70
|
+
loadController(): Promise<void>;
|
|
71
|
+
middleware(): void;
|
|
72
|
+
Start(): this;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=BaseChyz.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseChyz.d.ts","sourceRoot":"","sources":["../src/BaseChyz.ts"],"names":[],"mappings":"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"}
|
package/dist/BaseChyz.js
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
/**
|
|
49
|
+
* https server
|
|
50
|
+
*/
|
|
51
|
+
const express_1 = __importDefault(require("express"));
|
|
52
|
+
const https_1 = require("https");
|
|
53
|
+
const http_1 = require("http");
|
|
54
|
+
/**
|
|
55
|
+
* Freamwork
|
|
56
|
+
*/
|
|
57
|
+
const base_1 = require("./base");
|
|
58
|
+
const Utils_1 = require("./requiments/Utils");
|
|
59
|
+
const calendar_1 = __importDefault(require("dayjs/plugin/calendar"));
|
|
60
|
+
const weekOfYear_1 = __importDefault(require("dayjs/plugin/weekOfYear"));
|
|
61
|
+
const isTomorrow_1 = __importDefault(require("dayjs/plugin/isTomorrow"));
|
|
62
|
+
const bodyParser = require("body-parser");
|
|
63
|
+
const fs = require("fs");
|
|
64
|
+
// const http_request = require('debug')('http:request')
|
|
65
|
+
// const http_request_body = http_request.extend('body')
|
|
66
|
+
// const http_request_headers = http_request.extend('headers')
|
|
67
|
+
const compression_1 = __importDefault(require("compression"));
|
|
68
|
+
// const fs = require('fs');
|
|
69
|
+
const ip_1 = __importDefault(require("ip"));
|
|
70
|
+
const cors_1 = __importDefault(require("cors"));
|
|
71
|
+
const method_override_1 = __importDefault(require("method-override"));
|
|
72
|
+
const Server = (0, express_1.default)();
|
|
73
|
+
const emitter = require('events').EventEmitter;
|
|
74
|
+
const em = new emitter();
|
|
75
|
+
/**
|
|
76
|
+
* set request id
|
|
77
|
+
*/
|
|
78
|
+
Object.defineProperty(Server.request, 'reqId', {
|
|
79
|
+
configurable: true,
|
|
80
|
+
enumerable: true,
|
|
81
|
+
writable: true
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(Server.request, 'user', {
|
|
84
|
+
configurable: true,
|
|
85
|
+
enumerable: true,
|
|
86
|
+
writable: true
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(Server.request, 'identity', {
|
|
89
|
+
configurable: true,
|
|
90
|
+
enumerable: true,
|
|
91
|
+
writable: true
|
|
92
|
+
});
|
|
93
|
+
const validate_js_1 = __importDefault(require("validate.js"));
|
|
94
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
95
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
96
|
+
const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
|
|
97
|
+
dayjs_1.default.extend(utc_1.default);
|
|
98
|
+
dayjs_1.default.extend(relativeTime_1.default);
|
|
99
|
+
dayjs_1.default.extend(isTomorrow_1.default);
|
|
100
|
+
dayjs_1.default.extend(calendar_1.default);
|
|
101
|
+
dayjs_1.default.extend(weekOfYear_1.default);
|
|
102
|
+
/**
|
|
103
|
+
* Use
|
|
104
|
+
* selectedBox: {
|
|
105
|
+
* array: {
|
|
106
|
+
* id: {
|
|
107
|
+
* numericality: {
|
|
108
|
+
* onlyInteger: true,
|
|
109
|
+
* greaterThan: 0
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* },
|
|
114
|
+
* @param arrayItems
|
|
115
|
+
* @param itemConstraints
|
|
116
|
+
*/
|
|
117
|
+
validate_js_1.default.validators.array = (arrayItems, itemConstraints) => {
|
|
118
|
+
if (!Utils_1.Utils.isArray(arrayItems))
|
|
119
|
+
return { errors: [{ error: 'in not array' }] };
|
|
120
|
+
const arrayItemErrors = arrayItems.reduce((errors, item, index) => {
|
|
121
|
+
const error = (0, validate_js_1.default)(item, itemConstraints);
|
|
122
|
+
if (error)
|
|
123
|
+
errors[index] = { error: error };
|
|
124
|
+
return errors;
|
|
125
|
+
}, {});
|
|
126
|
+
return Utils_1.Utils.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
|
|
127
|
+
};
|
|
128
|
+
validate_js_1.default.validators.tokenString = (items, itemConstraints) => {
|
|
129
|
+
let arrayItems = items.split(",");
|
|
130
|
+
const arrayItemErrors = arrayItems.reduce((errors, item, index) => {
|
|
131
|
+
const error = (0, validate_js_1.default)(item, itemConstraints);
|
|
132
|
+
if (error)
|
|
133
|
+
errors[index] = { error: error };
|
|
134
|
+
return errors;
|
|
135
|
+
}, {});
|
|
136
|
+
return Utils_1.Utils.isEmpty(arrayItemErrors) ? null : { errors: arrayItemErrors };
|
|
137
|
+
};
|
|
138
|
+
validate_js_1.default.extend(validate_js_1.default.validators.datetime, {
|
|
139
|
+
// The value is guaranteed not to be null or undefined but otherwise it
|
|
140
|
+
// could be anything.
|
|
141
|
+
parse: function (value, options) {
|
|
142
|
+
return +(0, dayjs_1.default)().utc(value);
|
|
143
|
+
},
|
|
144
|
+
// Input is a unix timestamp
|
|
145
|
+
format: function (value, options) {
|
|
146
|
+
const format = options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss";
|
|
147
|
+
return (0, dayjs_1.default)().utc(value).format(format);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
class BaseChyz {
|
|
151
|
+
constructor() {
|
|
152
|
+
this._port = 3001;
|
|
153
|
+
this._controllerpath = "Controllers";
|
|
154
|
+
}
|
|
155
|
+
static get EventEmitter() {
|
|
156
|
+
return this._EventEmitter;
|
|
157
|
+
}
|
|
158
|
+
static set EventEmitter(value) {
|
|
159
|
+
this._EventEmitter = value;
|
|
160
|
+
}
|
|
161
|
+
get controllerpath() {
|
|
162
|
+
return this._controllerpath;
|
|
163
|
+
}
|
|
164
|
+
set controllerpath(value) {
|
|
165
|
+
this._controllerpath = value;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
170
|
+
init() {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
/**
|
|
173
|
+
* server port setting
|
|
174
|
+
*/
|
|
175
|
+
if (this.config.hasOwnProperty("port"))
|
|
176
|
+
this.port = this.config.port;
|
|
177
|
+
/**
|
|
178
|
+
* controller path
|
|
179
|
+
*/
|
|
180
|
+
if (this.config.controllerpath) {
|
|
181
|
+
this.controllerpath = this.config.controllerpath;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Model Register
|
|
185
|
+
*/
|
|
186
|
+
this.loadModels();
|
|
187
|
+
/**
|
|
188
|
+
* Express Server
|
|
189
|
+
*/
|
|
190
|
+
this.middleware();
|
|
191
|
+
/**
|
|
192
|
+
* Load Controller
|
|
193
|
+
*/
|
|
194
|
+
yield this.loadController();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Listen port number
|
|
199
|
+
* Server port number get
|
|
200
|
+
*/
|
|
201
|
+
get port() {
|
|
202
|
+
return this._port;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Listen port number
|
|
206
|
+
* Server port number setting
|
|
207
|
+
* @param value
|
|
208
|
+
*/
|
|
209
|
+
set port(value) {
|
|
210
|
+
this._port = value;
|
|
211
|
+
}
|
|
212
|
+
static get validate() {
|
|
213
|
+
return this._validate;
|
|
214
|
+
}
|
|
215
|
+
static set validate(value) {
|
|
216
|
+
this._validate = value;
|
|
217
|
+
}
|
|
218
|
+
app() {
|
|
219
|
+
return __awaiter(this, arguments, void 0, function* (config = {}) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_INIT_BEFORE, this, config);
|
|
222
|
+
/**
|
|
223
|
+
* Config set
|
|
224
|
+
*/
|
|
225
|
+
this.config = config;
|
|
226
|
+
/**
|
|
227
|
+
* log setting
|
|
228
|
+
*/
|
|
229
|
+
if (this.config.logs instanceof base_1.Logs) {
|
|
230
|
+
BaseChyz.logs = this.config.logs;
|
|
231
|
+
}
|
|
232
|
+
else if (!this.config.hasOwnProperty('logs')) {
|
|
233
|
+
BaseChyz.logs = new base_1.Logs();
|
|
234
|
+
}
|
|
235
|
+
let components = Utils_1.Utils.findKeyValue(config, "components");
|
|
236
|
+
if (components) {
|
|
237
|
+
/**
|
|
238
|
+
* first initial database component
|
|
239
|
+
*/
|
|
240
|
+
if (components.db) {
|
|
241
|
+
let comp = components['db'];
|
|
242
|
+
BaseChyz.debug("First initial database component ", "db");
|
|
243
|
+
try {
|
|
244
|
+
BaseChyz.components["db"] = Utils_1.Utils.createObject(new comp.class, comp);
|
|
245
|
+
(_a = BaseChyz.components["db"]) === null || _a === void 0 ? void 0 : _a.init();
|
|
246
|
+
delete components.db;
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
BaseChyz.error("Create Component Error", e);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const componentsKey in components) {
|
|
253
|
+
let comp = components[componentsKey];
|
|
254
|
+
BaseChyz.debug("Create Component ", componentsKey);
|
|
255
|
+
try {
|
|
256
|
+
BaseChyz.components[componentsKey] = Utils_1.Utils.createObject(new comp.class, comp);
|
|
257
|
+
(_b = BaseChyz.components[componentsKey]) === null || _b === void 0 ? void 0 : _b.init();
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
BaseChyz.error("Create Component Error", e);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
let middlewares = Utils_1.Utils.findKeyValue(config, "middlewares");
|
|
265
|
+
if (middlewares) {
|
|
266
|
+
for (const middlewareKey in middlewares) {
|
|
267
|
+
let middleware1 = middlewares[middlewareKey];
|
|
268
|
+
BaseChyz.debug("Create middlewares ", middlewareKey);
|
|
269
|
+
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
270
|
+
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
yield this.init();
|
|
274
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_INIT_AFTER, this, config);
|
|
275
|
+
return this;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
static trace(...args) {
|
|
279
|
+
BaseChyz.logs.fatal(...arguments);
|
|
280
|
+
}
|
|
281
|
+
static debug(...args) {
|
|
282
|
+
BaseChyz.logs.debug(...args);
|
|
283
|
+
}
|
|
284
|
+
static info(...args) {
|
|
285
|
+
BaseChyz.logs.info(...args);
|
|
286
|
+
}
|
|
287
|
+
static warn(...args) {
|
|
288
|
+
BaseChyz.logs.warn(...args);
|
|
289
|
+
}
|
|
290
|
+
static error(...args) {
|
|
291
|
+
BaseChyz.logs.error(...args);
|
|
292
|
+
}
|
|
293
|
+
static fatal(...args) {
|
|
294
|
+
BaseChyz.logs.fatal(...args);
|
|
295
|
+
}
|
|
296
|
+
static warning(...args) {
|
|
297
|
+
BaseChyz.logs.warn(...args);
|
|
298
|
+
}
|
|
299
|
+
static t(text, params) {
|
|
300
|
+
if (text == "")
|
|
301
|
+
return;
|
|
302
|
+
// let lang = require("@root/locales/tr/translation.json");
|
|
303
|
+
let lang = {};
|
|
304
|
+
if (lang.hasOwnProperty(text)) {
|
|
305
|
+
text = lang[text];
|
|
306
|
+
}
|
|
307
|
+
return text.tokenReplace(params);
|
|
308
|
+
}
|
|
309
|
+
errorLogger(error, req, res, next) {
|
|
310
|
+
BaseChyz.error(error);
|
|
311
|
+
next(error); // forward to next middleware
|
|
312
|
+
}
|
|
313
|
+
errorResponder(error, req, res, next) {
|
|
314
|
+
if (error.type == 'redirect')
|
|
315
|
+
res.redirect('/error');
|
|
316
|
+
else if (error.type == 'time-out') // arbitrary condition check
|
|
317
|
+
res.status(408).json(error);
|
|
318
|
+
else
|
|
319
|
+
next(error); // forwarding exceptional case to fail-safe middleware
|
|
320
|
+
}
|
|
321
|
+
errorHandler(err, req, res, next) {
|
|
322
|
+
if (res.headersSent) {
|
|
323
|
+
return next(err);
|
|
324
|
+
}
|
|
325
|
+
res.status(500).json({ error: err });
|
|
326
|
+
}
|
|
327
|
+
static getComponent(key) {
|
|
328
|
+
var _a;
|
|
329
|
+
return (_a = BaseChyz.components[key]) !== null && _a !== void 0 ? _a : null;
|
|
330
|
+
}
|
|
331
|
+
static getMiddlewares(key) {
|
|
332
|
+
var _a;
|
|
333
|
+
return (_a = BaseChyz.middlewares[key]) !== null && _a !== void 0 ? _a : null;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* load model
|
|
337
|
+
*/
|
|
338
|
+
loadModels() {
|
|
339
|
+
let models = {};
|
|
340
|
+
let path = `${this._controllerpath}/../Models`;
|
|
341
|
+
if (fs.existsSync(path)) {
|
|
342
|
+
fs.readdirSync(path).forEach((file) => {
|
|
343
|
+
if (file !== "index.ts") {
|
|
344
|
+
let model = require(`${path}/${file}`);
|
|
345
|
+
// @ts-ignore
|
|
346
|
+
let className = file.split(".")[0] + "Class";
|
|
347
|
+
if (model[className])
|
|
348
|
+
models[className.replace("Class", "")] = new model[className];
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
/**
|
|
352
|
+
*
|
|
353
|
+
*/
|
|
354
|
+
base_1.ModelManager._register(models);
|
|
355
|
+
for (const key of Object.keys(base_1.ModelManager)) {
|
|
356
|
+
if (key != "_register") {
|
|
357
|
+
base_1.ModelManager[key].init();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
BaseChyz.error("Model folder not found");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
beforeMiddleware(req, res, next, instance, route) {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
BaseChyz.debug(`${instance.id}/${route.path}->beforeMiddleware trigger`);
|
|
368
|
+
// http_request_body("Request body " + JSON.stringify(req.body))
|
|
369
|
+
// http_request_headers("Request header " + JSON.stringify(req.headers))
|
|
370
|
+
try {
|
|
371
|
+
yield instance.beforeAction(route, req, res);
|
|
372
|
+
next();
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
BaseChyz.error(e);
|
|
376
|
+
if (e instanceof base_1.BaseError) {
|
|
377
|
+
res.status((e === null || e === void 0 ? void 0 : e.statusCode) || 500);
|
|
378
|
+
res.json(e.toJSON());
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
res.json(e);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
responseHandler(req, res, next, instance, route) {
|
|
387
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
388
|
+
BaseChyz.debug(`${instance.id}/${route.path}->responseHandler trigger`);
|
|
389
|
+
try {
|
|
390
|
+
// @ts-ignore
|
|
391
|
+
yield instance[route.methodName](req, res, next);
|
|
392
|
+
next();
|
|
393
|
+
}
|
|
394
|
+
catch (e) {
|
|
395
|
+
BaseChyz.error(e);
|
|
396
|
+
if (e instanceof base_1.BaseError) {
|
|
397
|
+
res.status((e === null || e === void 0 ? void 0 : e.statusCode) || 500);
|
|
398
|
+
res.json(e.toJSON());
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
res.json(e);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
afterMiddleware(req, res, next, instance, route) {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
+
BaseChyz.debug(`${instance.id}/${route.path}->afterMiddleware trigger`);
|
|
409
|
+
try {
|
|
410
|
+
yield instance.afterAction(route, req, res);
|
|
411
|
+
}
|
|
412
|
+
catch (e) {
|
|
413
|
+
BaseChyz.error(e);
|
|
414
|
+
if (e instanceof base_1.BaseError) {
|
|
415
|
+
res.status((e === null || e === void 0 ? void 0 : e.statusCode) || 500);
|
|
416
|
+
res.json(e.toJSON());
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
res.json(e);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* load contoller
|
|
426
|
+
*/
|
|
427
|
+
loadController() {
|
|
428
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
429
|
+
// let articlesEndpoints: string[] = [];
|
|
430
|
+
for (const file of fs.readdirSync(`${this._controllerpath}/`)) {
|
|
431
|
+
// let controller = require(`${this._controllerpath}/${file}`);
|
|
432
|
+
let controller = (yield Promise.resolve(`${`${this._controllerpath}/${file}`}`).then(s => __importStar(require(s))));
|
|
433
|
+
if (controller[file.replace(".ts", "")]) {
|
|
434
|
+
controller = controller[file.replace(".ts", "")];
|
|
435
|
+
}
|
|
436
|
+
else if (controller.default) {
|
|
437
|
+
controller = controller.default;
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
throw new base_1.InvalidConfigException(BaseChyz.t(`Invalid Controller ${file}`));
|
|
441
|
+
}
|
|
442
|
+
// This is our instantiated class
|
|
443
|
+
const instance = new controller();
|
|
444
|
+
BaseChyz.controllers.push(instance);
|
|
445
|
+
// The prefix saved to our controller
|
|
446
|
+
const prefix = Reflect.getMetadata('prefix', controller);
|
|
447
|
+
// Our `routes` array containing all our routes for this controller
|
|
448
|
+
const routes = Reflect.getMetadata('routes', controller);
|
|
449
|
+
BaseChyz.debug("Controller load ", controller.name, `(${prefix})`);
|
|
450
|
+
if (routes) {
|
|
451
|
+
routes.forEach(route => {
|
|
452
|
+
route.id = (route.path == "/" || route.path == "") ? instance.defaultAction : route.path;
|
|
453
|
+
BaseChyz.debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
|
|
454
|
+
BaseChyz.propvider[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`), (req, res, next) => this.beforeMiddleware(req, res, next, instance, route), (req, res, next) => this.responseHandler(req, res, next, instance, route), (req, res, next) => this.afterMiddleware(req, res, next, instance, route));
|
|
455
|
+
// BaseChyz.propvider[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`),
|
|
456
|
+
// async (req: Request, res: Response, next: NextFunction) => {
|
|
457
|
+
// try {
|
|
458
|
+
// BaseChyz.debug(`Call Request id ${actionId}`)
|
|
459
|
+
// http_request_body("Request body " + JSON.stringify(req.body))
|
|
460
|
+
// http_request_headers("Request header " + JSON.stringify(req.headers))
|
|
461
|
+
// await instance.beforeAction(route, req, res);
|
|
462
|
+
// next()
|
|
463
|
+
// } catch (e: any) {
|
|
464
|
+
//
|
|
465
|
+
// BaseChyz.error(e)
|
|
466
|
+
// if (e instanceof BaseError) {
|
|
467
|
+
// res.status(e?.statusCode || 500)
|
|
468
|
+
// res.json(e.toJSON())
|
|
469
|
+
// } else {
|
|
470
|
+
// res.json(e)
|
|
471
|
+
// }
|
|
472
|
+
//
|
|
473
|
+
// // / next(e)
|
|
474
|
+
// }
|
|
475
|
+
//
|
|
476
|
+
// },
|
|
477
|
+
// async (req: Request, res: Response, next: NextFunction) => {
|
|
478
|
+
// try {
|
|
479
|
+
// // @ts-ignore
|
|
480
|
+
// BaseChyz.debug("Request ID ", req.reqId)
|
|
481
|
+
// // @ts-ignore
|
|
482
|
+
// await instance[route.methodName](req, res, next);
|
|
483
|
+
// instance.afterAction(route, req, res);
|
|
484
|
+
// } catch (e) {
|
|
485
|
+
// BaseChyz.error(e)
|
|
486
|
+
// if (e instanceof BaseError) {
|
|
487
|
+
// res.status(e.statusCode || 500)
|
|
488
|
+
// res.json(e.toJSON())
|
|
489
|
+
// } else {
|
|
490
|
+
// res.json(e)
|
|
491
|
+
// }
|
|
492
|
+
// }
|
|
493
|
+
// })
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
middleware() {
|
|
500
|
+
var _a;
|
|
501
|
+
BaseChyz.propvider.use(bodyParser.json({ limit: '1mb' }));
|
|
502
|
+
BaseChyz.propvider.use(bodyParser.urlencoded({ limit: '1mb', extended: true })); // support encoded bodies
|
|
503
|
+
BaseChyz.propvider.use((0, method_override_1.default)());
|
|
504
|
+
BaseChyz.propvider.use((0, cors_1.default)());
|
|
505
|
+
//
|
|
506
|
+
// // CORS
|
|
507
|
+
// BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
508
|
+
// // @ts-ignore
|
|
509
|
+
// req.reqId = Utils.uniqueId("chyzzzz_")
|
|
510
|
+
// res.setHeader('Content-Type', 'application/json');
|
|
511
|
+
// res.setHeader("Access-Control-Allow-Origin", "*");
|
|
512
|
+
// res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
513
|
+
// res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
|
|
514
|
+
// res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
|
|
515
|
+
// next();
|
|
516
|
+
// });
|
|
517
|
+
//
|
|
518
|
+
// compress all responses
|
|
519
|
+
const shouldCompress = (req, res) => {
|
|
520
|
+
// don't compress responses explicitly asking not
|
|
521
|
+
if (req.headers["x-no-compression"] || res.getHeader('Content-Type') === 'text/event-stream') {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
// use compression filter function
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
return compression_1.default.filter(req, res);
|
|
527
|
+
};
|
|
528
|
+
// @ts-ignore
|
|
529
|
+
BaseChyz.propvider.use((0, compression_1.default)({ filter: shouldCompress }));
|
|
530
|
+
//
|
|
531
|
+
// //static file path
|
|
532
|
+
if (this.config.staticFilePath) {
|
|
533
|
+
BaseChyz.info('Static file path', this.config.staticFilePath);
|
|
534
|
+
BaseChyz.propvider.use(express_1.default.static(this.config.staticFilePath));
|
|
535
|
+
}
|
|
536
|
+
//Middlewares
|
|
537
|
+
for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
|
|
538
|
+
if ((_a = BaseChyz.middlewares[middleware1]) === null || _a === void 0 ? void 0 : _a.keycloak) {
|
|
539
|
+
let keycloak = BaseChyz.middlewares[middleware1].keycloak;
|
|
540
|
+
//@ts-ignore
|
|
541
|
+
BaseChyz.propvider.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
BaseChyz.propvider.use(BaseChyz.middlewares[middleware1]);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
BaseChyz.propvider.use(this.errorResponder);
|
|
548
|
+
BaseChyz.propvider.use(this.errorHandler);
|
|
549
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_MIDDLEWARE, this);
|
|
550
|
+
}
|
|
551
|
+
Start() {
|
|
552
|
+
var _a, _b;
|
|
553
|
+
BaseChyz.info("Express Server Starting");
|
|
554
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_BEFORE_START, this);
|
|
555
|
+
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.ssl) {
|
|
556
|
+
BaseChyz.httpServer = (0, https_1.createServer)((_b = this.config) === null || _b === void 0 ? void 0 : _b.ssl, BaseChyz.propvider);
|
|
557
|
+
BaseChyz.httpServer.listen(this._port, () => {
|
|
558
|
+
BaseChyz.info("Express Server Start ");
|
|
559
|
+
BaseChyz.info(`Liten Port ${this._port}`);
|
|
560
|
+
BaseChyz.info(`https://localhost:${this._port}`);
|
|
561
|
+
BaseChyz.info(`https://${ip_1.default.address()}:${this._port}`);
|
|
562
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_START, this);
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
BaseChyz.httpServer = (0, http_1.createServer)(BaseChyz.propvider);
|
|
567
|
+
BaseChyz.httpServer.listen(this._port, () => {
|
|
568
|
+
BaseChyz.info("Express Server Start ");
|
|
569
|
+
BaseChyz.info(`Liten Port ${this._port}`);
|
|
570
|
+
BaseChyz.info(`http://localhost:${this._port}`);
|
|
571
|
+
BaseChyz.info(`http://${ip_1.default.address()}:${this._port}`);
|
|
572
|
+
BaseChyz.EventEmitter.emit(base_1.CEvents.ON_START, this);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
return this;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
BaseChyz.propvider = Server;
|
|
579
|
+
BaseChyz.date = dayjs_1.default;
|
|
580
|
+
BaseChyz.logs = new base_1.Logs();
|
|
581
|
+
BaseChyz._validate = validate_js_1.default;
|
|
582
|
+
BaseChyz.controllers = [];
|
|
583
|
+
BaseChyz.components = {};
|
|
584
|
+
BaseChyz.middlewares = {};
|
|
585
|
+
BaseChyz._EventEmitter = em;
|
|
586
|
+
exports.default = BaseChyz;
|