linker-api 1.0.0 → 1.0.2
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/lib/container/expose-api.js +56 -0
- package/dist/lib/container/expose-api.js.map +1 -0
- package/dist/lib/container/service-context.js +194 -0
- package/dist/lib/container/service-context.js.map +1 -0
- package/dist/lib/factory/factory.js +4 -48
- package/dist/lib/factory/factory.js.map +1 -1
- package/dist/lib/loader/express-loader.js +147 -0
- package/dist/lib/loader/express-loader.js.map +1 -0
- package/dist/lib/loader/load-balancer.js +81 -0
- package/dist/lib/loader/load-balancer.js.map +1 -0
- package/dist/lib/logger/app-logger.js +28 -0
- package/dist/lib/logger/app-logger.js.map +1 -0
- package/dist/public-api.js +1 -1
- package/package.json +8 -1
- package/src/lib/container/expose-api.ts +44 -0
- package/src/lib/container/service-context.ts +174 -0
- package/src/lib/factory/factory.ts +5 -11
- package/src/lib/loader/express-loader.ts +93 -0
- package/src/lib/loader/load-balancer.ts +65 -0
- package/src/lib/logger/app-logger.ts +20 -0
- package/src/public-api.ts +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ExposeApi = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
class ExposeApi {
|
|
9
|
+
constructor(AppConfig) {
|
|
10
|
+
this.AppConfig = AppConfig;
|
|
11
|
+
}
|
|
12
|
+
registerControllers(apiDir, config) {
|
|
13
|
+
apiDir = apiDir.replace('server', '');
|
|
14
|
+
let apiScanned = this.AppConfig.API_SCAN;
|
|
15
|
+
for (let scanned of apiScanned) {
|
|
16
|
+
let controllerDir = `${apiDir}/dist/${scanned}`;
|
|
17
|
+
//console.log(`controllerDir : ${controllerDir}`)
|
|
18
|
+
if (fs_1.default.existsSync(controllerDir)) {
|
|
19
|
+
let cntrlFiles = this.getFiles(controllerDir);
|
|
20
|
+
//console.log(`cntrlFiles : ${cntrlFiles}`)
|
|
21
|
+
for (let i in cntrlFiles) {
|
|
22
|
+
let cntrlFile = cntrlFiles[i];
|
|
23
|
+
let cntrlClass = require(cntrlFile);
|
|
24
|
+
if (typeof (Object.values(cntrlClass)[0]) === 'function')
|
|
25
|
+
config.register(Object.values(cntrlClass)[0]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
getFiles(dir, files_) {
|
|
31
|
+
files_ = files_ || [];
|
|
32
|
+
var files;
|
|
33
|
+
try {
|
|
34
|
+
files = fs_1.default.readdirSync(dir);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
}
|
|
38
|
+
if (!files) {
|
|
39
|
+
files = [];
|
|
40
|
+
}
|
|
41
|
+
for (var i in files) {
|
|
42
|
+
let file = files[i];
|
|
43
|
+
var name = dir + '/' + file;
|
|
44
|
+
if (fs_1.default.statSync(name).isDirectory()) {
|
|
45
|
+
this.getFiles(name, files_);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (file.endsWith('.js'))
|
|
49
|
+
files_.push(name);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return files_;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ExposeApi = ExposeApi;
|
|
56
|
+
//# sourceMappingURL=expose-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expose-api.js","sourceRoot":"","sources":["../../../src/lib/container/expose-api.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,MAAa,SAAS;IAClB,YAAoB,SAAa;QAAb,cAAS,GAAT,SAAS,CAAI;IAAE,CAAC;IACpC,mBAAmB,CAAC,MAAM,EAAE,MAAM;QAC9B,MAAM,GAAG,MA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,GAAG,GAAG,IAAI,CAAC;YAC5B,IAAI,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAC,CAAC;gBACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACJ,IAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;oBACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA1CD,8BA0CC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ServiceContext = void 0;
|
|
13
|
+
class ServiceContext {
|
|
14
|
+
constructor(app, express, authorizer) {
|
|
15
|
+
this.app = app;
|
|
16
|
+
this.express = express;
|
|
17
|
+
this.authorizer = authorizer;
|
|
18
|
+
this.serviceMap = {};
|
|
19
|
+
this.SchemaConfig = [];
|
|
20
|
+
}
|
|
21
|
+
register(controllerClass) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
try {
|
|
24
|
+
//console.log(`registration of controllers ${controllerClass.name}`)
|
|
25
|
+
//console.log(`Controller metadata OLD: ${JSON.stringify(controllerClass.prototype)}`)
|
|
26
|
+
let controller = new controllerClass(this.app);
|
|
27
|
+
let cntrlMetadata = controllerClass.prototype;
|
|
28
|
+
let cntrlUri = (_a = cntrlMetadata.metadata) === null || _a === void 0 ? void 0 : _a.baseUri;
|
|
29
|
+
if (cntrlUri) {
|
|
30
|
+
//let controller = new controllerClass(app);
|
|
31
|
+
//console.log(`Controller metadata: ${controller.metadata}`)
|
|
32
|
+
//console.log(`Controller method metadata: ${JSON.stringify(controller['getDispensaryEmployees'])}`)
|
|
33
|
+
if (controller.metadata) {
|
|
34
|
+
let router = this.express.Router();
|
|
35
|
+
this.serviceMap[controller.metadata.baseUri] = controller;
|
|
36
|
+
controller.request = this.request.bind(this);
|
|
37
|
+
if (!controller.router) {
|
|
38
|
+
//console.log(`registration of controllers ${controller.metadata.baseUri}`)
|
|
39
|
+
if (controller.metadata.baseUri)
|
|
40
|
+
this.app.use(controller.metadata.baseUri, router);
|
|
41
|
+
controller.router = router;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
controller.getSchemaConfig = () => {
|
|
46
|
+
return this.SchemaConfig;
|
|
47
|
+
};
|
|
48
|
+
let schema = (_b = cntrlMetadata.metadata) === null || _b === void 0 ? void 0 : _b.schema;
|
|
49
|
+
if (schema) {
|
|
50
|
+
this.addSchemaConfig(schema);
|
|
51
|
+
}
|
|
52
|
+
//console.log(`Controller router: ${controller}`)
|
|
53
|
+
let protoOfTest = Object.getPrototypeOf(controller);
|
|
54
|
+
let methodMap = Object.getOwnPropertyNames(protoOfTest).filter(item => !['constructor', 'metadata'].includes(item));
|
|
55
|
+
for (let idx = 0; idx < methodMap.length; idx++) {
|
|
56
|
+
let method = methodMap[idx];
|
|
57
|
+
if (schema) {
|
|
58
|
+
this.addSchemaMethod(method, controller, schema);
|
|
59
|
+
}
|
|
60
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.id) !== 'common') {
|
|
61
|
+
this.registerMethod(method, controller, controller.router);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//console.log('controller.metadata.baseUri '+controller.metadata?.baseUri);
|
|
65
|
+
//console.log('register Controller :: '+controller?.router?.stack);
|
|
66
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.id) === 'common') {
|
|
67
|
+
this.commonService = controller;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.log('register Controller Error :: ' + err.stack);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
addSchemaConfig(schema) {
|
|
75
|
+
//console.log(`schema `, schema)
|
|
76
|
+
let idx = this.SchemaConfig.findIndex(item => (item === null || item === void 0 ? void 0 : item.id) === schema.id);
|
|
77
|
+
if (idx === -1) {
|
|
78
|
+
if (this.commonService) {
|
|
79
|
+
schema.table = schema.table.concat(this.commonService.getSchemaConfig()[0].table);
|
|
80
|
+
}
|
|
81
|
+
this.SchemaConfig.push(schema);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
addPreProcessor(metadata, controller, schema) {
|
|
85
|
+
let table = schema.table.find(item => (item === null || item === void 0 ? void 0 : item.id) === metadata.uriMethod);
|
|
86
|
+
if (table) {
|
|
87
|
+
if (!table.preProcessors)
|
|
88
|
+
table.preProcessors = [];
|
|
89
|
+
table.preProcessors.push(controller[metadata.actualMethod].bind(controller));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
addPostProcessor(metadata, controller, schema) {
|
|
93
|
+
let table = schema.table.find(item => (item === null || item === void 0 ? void 0 : item.id) === metadata.uriMethod);
|
|
94
|
+
if (table) {
|
|
95
|
+
if (!table.postProcessors)
|
|
96
|
+
table.postProcessors = [];
|
|
97
|
+
table.postProcessors.push(controller[metadata.actualMethod].bind(controller));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
addSchemaMethod(method, controller, schema) {
|
|
101
|
+
let metadata = controller[method].metadata;
|
|
102
|
+
//console.log('metadata ', metadata)
|
|
103
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.isExecutor) {
|
|
104
|
+
let idx = schema.table.findIndex(elem => (elem === null || elem === void 0 ? void 0 : elem.id) === metadata.uriPath);
|
|
105
|
+
if (idx === -1) {
|
|
106
|
+
//console.log('isExecutor')
|
|
107
|
+
schema.table.push({
|
|
108
|
+
id: metadata.uriPath.replace('/', ''),
|
|
109
|
+
executor: controller[metadata.actualMethod].bind(controller)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.isPreProcessor) {
|
|
114
|
+
this.addPreProcessor(metadata, controller, schema);
|
|
115
|
+
}
|
|
116
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.isPostProcessor) {
|
|
117
|
+
this.addPostProcessor(metadata, controller, schema);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
registerMethod(method, controller, router) {
|
|
121
|
+
let metadata = controller[method].metadata;
|
|
122
|
+
//console.log('registerMethod :: '+method);
|
|
123
|
+
/*if(controllerClass.name === 'Master' && metadata){
|
|
124
|
+
console.log(`Controller method metadata: ${JSON.stringify(metadata)}`)
|
|
125
|
+
console.log(`Controller method metadata: ${controller[method]}`)
|
|
126
|
+
}*/
|
|
127
|
+
let secureCallback = this.authorizer; //Middleware.verifyToken.bind(Middleware);
|
|
128
|
+
if (metadata && router) {
|
|
129
|
+
//console.log(`metadata `, metadata)
|
|
130
|
+
//console.log(`metadata.unsecured ${metadata.unsecured}`)
|
|
131
|
+
if (metadata.unsecured || !this.authorizer) {
|
|
132
|
+
secureCallback = (req, res, next) => { next(); };
|
|
133
|
+
}
|
|
134
|
+
let callerMethod = (req, res, next) => {
|
|
135
|
+
controller[method].apply(controller, [req, res, next]);
|
|
136
|
+
};
|
|
137
|
+
//let callerMethod = controller[method].bind(controller);
|
|
138
|
+
switch (metadata.uriMethod) {
|
|
139
|
+
case 'post':
|
|
140
|
+
router.post(metadata.uriPath, secureCallback, callerMethod);
|
|
141
|
+
break;
|
|
142
|
+
case 'put':
|
|
143
|
+
router.put(metadata.uriPath, secureCallback, callerMethod);
|
|
144
|
+
break;
|
|
145
|
+
case 'delete':
|
|
146
|
+
router.delete(metadata.uriPath, secureCallback, callerMethod);
|
|
147
|
+
break;
|
|
148
|
+
case 'get':
|
|
149
|
+
router.get(metadata.uriPath, secureCallback, callerMethod);
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
router.get(metadata.uriPath, secureCallback, callerMethod);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
request(options) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
let uris = options.url.split('/');
|
|
159
|
+
let controller = this.serviceMap[`/${uris[1]}`];
|
|
160
|
+
let component;
|
|
161
|
+
let req = {
|
|
162
|
+
attributes: options.attributes,
|
|
163
|
+
body: options.body,
|
|
164
|
+
headers: options.headers,
|
|
165
|
+
method: options.method
|
|
166
|
+
};
|
|
167
|
+
if (!controller) {
|
|
168
|
+
controller = this.serviceMap[`/`];
|
|
169
|
+
component = controller.router.stack.find(item => item.route.path === `/:service/:operation`);
|
|
170
|
+
req.params = { service: uris[1], operation: uris[2] };
|
|
171
|
+
}
|
|
172
|
+
if (controller && !component) {
|
|
173
|
+
component = controller.router.stack.find(item => item.route.path === `/${uris[2]}`);
|
|
174
|
+
}
|
|
175
|
+
if (component) {
|
|
176
|
+
req.path = component.route.path;
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
let result = {
|
|
179
|
+
send: (data) => {
|
|
180
|
+
resolve(data);
|
|
181
|
+
},
|
|
182
|
+
status: (status) => {
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
component.handle(req, result);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return { status: 1 };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.ServiceContext = ServiceContext;
|
|
194
|
+
//# sourceMappingURL=service-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-context.js","sourceRoot":"","sources":["../../../src/lib/container/service-context.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAa,cAAc;IAIvB,YAAoB,GAAG,EAAU,OAAO,EAAU,UAAW;QAAzC,QAAG,GAAH,GAAG,CAAA;QAAU,YAAO,GAAP,OAAO,CAAA;QAAU,eAAU,GAAV,UAAU,CAAC;QAH7D,eAAU,GAAG,EAAE,CAAC;QAChB,iBAAY,GAAG,EAAE,CAAC;IAE6C,CAAC;IAC/D,QAAQ,CAAC,eAAe;;QAC3B,IAAG,CAAC;YACM,oEAAoE;YACpE,sFAAsF;YACtF,IAAI,UAAU,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,aAAa,GAAG,eAAe,CAAC,SAAS,CAAC;YAC9C,IAAI,QAAQ,GAAG,MAAA,aAAa,CAAC,QAAQ,0CAAE,OAAO,CAAC;YAE/C,IAAG,QAAQ,EAAC,CAAC;gBACT,4CAA4C;gBAC5C,4DAA4D;gBAC5D,oGAAoG;gBACpG,IAAG,UAAU,CAAC,QAAQ,EAAC,CAAC;oBACpB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;oBACnC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;oBAC1D,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC7C,IAAG,CAAC,UAAU,CAAC,MAAM,EAAC,CAAC;wBACnB,2EAA2E;wBAC3E,IAAG,UAAU,CAAC,QAAQ,CAAC,OAAO;4BAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;wBACtD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AC,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtF,CAAC;YACD,IAAG,SAAS,EAAC,CAAC;gBACV,GAAG,CAAC,IAAI,GAAE,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAC,EAAE;oBAClC,IAAI,MAAM,GAAG;wBACT,IAAI,EAAE,CAAC,IAAI,EAAC,EAAE;4BACV,OAAO,CAAC,IAAI,CAAC,CAAC;wBAClB,CAAC;wBACD,MAAM,EAAE,CAAC,MAAM,EAAC,EAAE;4BACd,OAAO,MAAM,CAAC;wBAClB,CAAC;qBACJ,CAAC;oBACF,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBAClC,CAAC,CAAC,CAAA;YACN,CAAC;YACD,OAAO,EAAC,MAAM,EAAE,CAAC,EAAC,CAAC;QACvB,CAAC;KAAA;CACJ;AA7KD,wCA6KC"}
|
|
@@ -1,37 +1,4 @@
|
|
|
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 () {
|
|
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -43,23 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
10
|
};
|
|
44
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
12
|
exports.Factory = void 0;
|
|
13
|
+
const express_loader_1 = require("../loader/express-loader");
|
|
46
14
|
class Factory {
|
|
47
|
-
static
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
let comm = yield Promise.resolve().then(() => __importStar(require('../../lib/database/schema/common-service')));
|
|
50
|
-
return comm.CommonService;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
static getLinkConfig() {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
let linkConfig = yield Promise.resolve().then(() => __importStar(require('../../lib/config/link-config')));
|
|
56
|
-
return linkConfig.LinkConfig;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
static getApiService() {
|
|
15
|
+
static getLinkLoader() {
|
|
60
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
let svc =
|
|
62
|
-
return svc
|
|
17
|
+
let svc = new express_loader_1.ExpressLoader();
|
|
18
|
+
return svc;
|
|
63
19
|
});
|
|
64
20
|
}
|
|
65
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/lib/factory/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/lib/factory/factory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAyD;AAEzD,MAAa,OAAO;IAChB,MAAM,CAAO,aAAa;;YACtB,IAAI,GAAG,GAAG,IAAI,8BAAa,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;CACJ;AALD,0BAKC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
exports.ExpressLoader = void 0;
|
|
49
|
+
const express_1 = __importDefault(require("express"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
52
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
53
|
+
const express_session_1 = __importDefault(require("express-session"));
|
|
54
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
55
|
+
const app_logger_1 = require("../logger/app-logger");
|
|
56
|
+
const service_context_1 = require("../container/service-context");
|
|
57
|
+
const expose_api_1 = require("../container/expose-api");
|
|
58
|
+
const link_config_1 = require("../config/link-config");
|
|
59
|
+
const load_balancer_1 = require("./load-balancer");
|
|
60
|
+
class ExpressLoader {
|
|
61
|
+
constructor() {
|
|
62
|
+
this.app = (0, express_1.default)();
|
|
63
|
+
this.app.use(body_parser_1.default.json({
|
|
64
|
+
limit: '500mb'
|
|
65
|
+
}));
|
|
66
|
+
this.app.use((0, cookie_parser_1.default)());
|
|
67
|
+
this.app.use(body_parser_1.default.urlencoded({
|
|
68
|
+
limit: '500mb',
|
|
69
|
+
parameterLimit: 100000,
|
|
70
|
+
extended: true
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
init(config, appDir, serviceDir, callback) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
let authType = config.authType || '0';
|
|
76
|
+
let threadPoolSize = config.threadPoolSize || 5;
|
|
77
|
+
let contextPath = config.baseUri;
|
|
78
|
+
this.app.use((0, express_session_1.default)(config.SESSION_CONFIG));
|
|
79
|
+
this.app.use((0, express_fileupload_1.default)());
|
|
80
|
+
console.log('contextPath ' + contextPath);
|
|
81
|
+
let router = express_1.default.Router();
|
|
82
|
+
let webDir = path_1.default.join(serviceDir, '../build');
|
|
83
|
+
router.use(express_1.default.static(webDir));
|
|
84
|
+
console.log(`IS_DEFAULT_AUTH :: ${authType}`);
|
|
85
|
+
console.log(`'0' === IS_DEFAULT_AUTH :: ${'0' === authType}`);
|
|
86
|
+
new app_logger_1.AppLogger(config.CUSTOMER_ID, appDir);
|
|
87
|
+
if ('0' === authType) {
|
|
88
|
+
const { Middleware } = require('tharak-auth');
|
|
89
|
+
Middleware.setAppDir(`${serviceDir}/dummy/dummy`);
|
|
90
|
+
let dbProviderId = `${config.appName}_DbProvider`;
|
|
91
|
+
if (config.linkedDBItem && config.linkedDBItem.dbId) {
|
|
92
|
+
link_config_1.LinkConfig.PROD_DB_CONFIGS[dbProviderId] = this.getDbOptions(config.linkedDBItem);
|
|
93
|
+
link_config_1.LinkConfig.DATABASE_PROVIDER = { id: config.linkedDBItem.dbId, configID: dbProviderId };
|
|
94
|
+
}
|
|
95
|
+
Middleware.setAppConfig(config);
|
|
96
|
+
this.serverApp = new service_context_1.ServiceContext(router, express_1.default, Middleware.verifyToken.bind(Middleware));
|
|
97
|
+
const { Login } = require('tharak-auth');
|
|
98
|
+
this.serverApp.register(Login);
|
|
99
|
+
Middleware.request = this.serverApp.request;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.serverApp = new service_context_1.ServiceContext(router, express_1.default);
|
|
103
|
+
}
|
|
104
|
+
this.serverApp.register(yield this.getCommonService());
|
|
105
|
+
this.serverApp.register(yield this.getApiService());
|
|
106
|
+
new expose_api_1.ExposeApi(config).registerControllers(serviceDir, this.serverApp);
|
|
107
|
+
/*let swaggerLinker = require('../swagger/swagger-linker');
|
|
108
|
+
swaggerLinker.init(contextPath, express);
|
|
109
|
+
swaggerLinker.use(this.app, '/doc');*/
|
|
110
|
+
this.app.use(contextPath, router);
|
|
111
|
+
let loadBalancer = new load_balancer_1.LoadBalancer(this.app);
|
|
112
|
+
var listenerPort = yield loadBalancer.create(threadPoolSize, config.serverPort || 0);
|
|
113
|
+
console.log(`${contextPath} listening`);
|
|
114
|
+
console.log(`{"SERVER_PORT":${listenerPort}}`);
|
|
115
|
+
callback(listenerPort);
|
|
116
|
+
this.app.use((error, request, response, next) => {
|
|
117
|
+
console.log(error.toString());
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getDbOptions(linkedDB) {
|
|
122
|
+
return {
|
|
123
|
+
user: linkedDB.dbUser,
|
|
124
|
+
password: linkedDB.dbPassword,
|
|
125
|
+
port: linkedDB.serverPort,
|
|
126
|
+
database: linkedDB.dbName,
|
|
127
|
+
server: linkedDB.serverName,
|
|
128
|
+
options: linkedDB.dbOptions,
|
|
129
|
+
pool: linkedDB.dbPoolConfig,
|
|
130
|
+
multipleStatements: linkedDB.dbMultipleStatements
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
getCommonService() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
let comm = yield Promise.resolve().then(() => __importStar(require('../../lib/database/schema/common-service')));
|
|
136
|
+
return comm.CommonService;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getApiService() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
let svc = yield Promise.resolve().then(() => __importStar(require('../../lib/dispatcher/health-service')));
|
|
142
|
+
return svc.HealthService;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.ExpressLoader = ExpressLoader;
|
|
147
|
+
//# sourceMappingURL=express-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express-loader.js","sourceRoot":"","sources":["../../../src/lib/loader/express-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,gDAAwB;AACxB,4EAA4C;AAC5C,kEAAyC;AACzC,sEAAuC;AACvC,8DAAqC;AACrC,qDAAiD;AACjD,kEAA8D;AAC9D,wDAAoD;AACpD,uDAAmD;AACnD,mDAA+C;AAE/C,MAAa,aAAa;IAGtB;QACI,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,qBAAU,CAAC,IAAI,CAAC;YAC7B,KAAK,EAAE,OAAO;SACb,CAAC,CAAC,CAAC;QACJ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,uBAAY,GAAE,CAAC,CAAC;QAC7B,IAAI,C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+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LoadBalancer = void 0;
|
|
16
|
+
const nebula_http_proxy_1 = __importDefault(require("nebula-http-proxy"));
|
|
17
|
+
const http_1 = __importDefault(require("http"));
|
|
18
|
+
class LoadBalancer {
|
|
19
|
+
constructor(app) {
|
|
20
|
+
this.app = app;
|
|
21
|
+
this.cur = 0;
|
|
22
|
+
this.servers = [];
|
|
23
|
+
this.numOfServers = 10;
|
|
24
|
+
}
|
|
25
|
+
create(threadPoolSize, serverPort) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
this.proxyServer = nebula_http_proxy_1.default.createProxyServer({
|
|
29
|
+
secure: false
|
|
30
|
+
});
|
|
31
|
+
if (threadPoolSize)
|
|
32
|
+
this.numOfServers = threadPoolSize;
|
|
33
|
+
this.load(this.numOfServers, this.app, this.servers);
|
|
34
|
+
let appRouteSvr = http_1.default.createServer({}, this.createServer.bind(this)).listen(serverPort, () => {
|
|
35
|
+
resolve(appRouteSvr.address().port);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
load(count, app, appSvrs) {
|
|
41
|
+
for (let idx = 0; idx < count; idx++) {
|
|
42
|
+
let server = app.listen(0, () => {
|
|
43
|
+
appSvrs.push('http://localhost:' + server.address().port);
|
|
44
|
+
return console.log(`server is listening on ${server.address().port}`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
createServer(req, res) {
|
|
49
|
+
try {
|
|
50
|
+
console.log('instance number :: ' + this.cur);
|
|
51
|
+
let routeSvr = this.servers[this.cur];
|
|
52
|
+
console.log('Router ' + routeSvr);
|
|
53
|
+
const start = Date.now();
|
|
54
|
+
// Add any needed fields to
|
|
55
|
+
this.proxyServer.web(req, res, { target: routeSvr });
|
|
56
|
+
this.proxyServer.on('error', (err, errRq, errRs) => {
|
|
57
|
+
console.log('Proxy error ' + err.toString());
|
|
58
|
+
errRs.writeHead(500, {
|
|
59
|
+
'Content-Type': 'text/plain'
|
|
60
|
+
});
|
|
61
|
+
errRs.end('Something went wrong. And we are reporting a custom error message.');
|
|
62
|
+
});
|
|
63
|
+
this.proxyServer.on('close', function (res, socket, head) {
|
|
64
|
+
// view disconnected websocket connections
|
|
65
|
+
console.log('Client disconnected');
|
|
66
|
+
});
|
|
67
|
+
this.cur = (this.cur + 1) % this.servers.length;
|
|
68
|
+
res.on('finish', () => {
|
|
69
|
+
console.log('Completed', req.method, req.url, Date.now() - start);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.log(err.toString());
|
|
74
|
+
res.status(500).send({
|
|
75
|
+
message: err.toString()
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.LoadBalancer = LoadBalancer;
|
|
81
|
+
//# sourceMappingURL=load-balancer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-balancer.js","sourceRoot":"","sources":["../../../src/lib/loader/load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,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBAClB,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;YACtE,CAAC,CAAC,CAAC;QACH,CAAC;QAAA,OAAM,GAAG,EAAC,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE;aAC1B,CAAC,CAAC;QACH,CAAC;IACL,CAAC;CACJ;AA9DD,oCA8DC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AppLogger = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const nebula_node_logger_1 = __importDefault(require("nebula-node-logger"));
|
|
9
|
+
class AppLogger {
|
|
10
|
+
constructor(customerId, appLogDir) {
|
|
11
|
+
appLogDir = `./appLogs/`;
|
|
12
|
+
if (!fs_1.default.existsSync(appLogDir)) {
|
|
13
|
+
fs_1.default.mkdirSync(appLogDir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
const opts = {
|
|
16
|
+
errorEventName: 'error',
|
|
17
|
+
logDirectory: appLogDir, // NOTE: folder must exist and be writable...
|
|
18
|
+
fileNamePattern: `${customerId}-<DATE>.log`,
|
|
19
|
+
dateFormat: 'YYYY.MM.DD-HHa'
|
|
20
|
+
};
|
|
21
|
+
const log = nebula_node_logger_1.default.createRollingFileLogger(opts);
|
|
22
|
+
console.log = log.info;
|
|
23
|
+
console.error = log.error;
|
|
24
|
+
console.debug = log.debug;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AppLogger = AppLogger;
|
|
28
|
+
//# sourceMappingURL=app-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-logger.js","sourceRoot":"","sources":["../../../src/lib/logger/app-logger.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,4EAA4C;AAC5C,MAAa,SAAS;IAClB,YAAY,UAAU,EAAE,SAAU;QAC9B,SAAS,GAAG,YAAY,CAAC;QACzB,IAAG,CAAC,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAC,CAAC;YAC1B,YAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,IAAI,GAAG;YACT,cAAc,EAAC,OAAO;YAClB,YAAY,EAAE,SAAS,EAAE,6CAA6C;YACtE,eAAe,EAAC,GAAG,UAAU,aAAa;YAC1C,UAAU,EAAC,gBAAgB;SAClC,CAAC;QACF,MAAM,GAAG,GAAG,4BAAU,CAAC,uBAAuB,CAAE,IAAI,CAAE,CAAC;QACvD,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;QACvB,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QAC1B,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IAC9B,CAAC;CACJ;AAjBD,8BAiBC"}
|
package/dist/public-api.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linker-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -22,10 +22,17 @@
|
|
|
22
22
|
"homepage": "https://github.com/thiragati-soft/linker-api#readme",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^20.12.7",
|
|
25
|
+
"cookie-parser": "^1.4.7",
|
|
26
|
+
"express": "^5.1.0",
|
|
27
|
+
"express-fileupload": "^1.5.2",
|
|
28
|
+
"express-session": "^1.18.2",
|
|
25
29
|
"fs-extra": "^11.3.2",
|
|
26
30
|
"mssql": "^12.0.0",
|
|
31
|
+
"nebula-http-proxy": "^0.0.2",
|
|
32
|
+
"nebula-node-logger": "^0.0.1",
|
|
27
33
|
"rimraf": "^6.1.0",
|
|
28
34
|
"tharak-api": "^0.0.7",
|
|
35
|
+
"tharak-auth": "^0.0.9",
|
|
29
36
|
"typescript": "^5.4.5"
|
|
30
37
|
}
|
|
31
38
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
export class ExposeApi {
|
|
3
|
+
constructor(private AppConfig:any){}
|
|
4
|
+
registerControllers(apiDir, config){
|
|
5
|
+
apiDir = apiDir.replace('server', '');
|
|
6
|
+
let apiScanned = this.AppConfig.API_SCAN;
|
|
7
|
+
for(let scanned of apiScanned){
|
|
8
|
+
let controllerDir = `${apiDir}/dist/${scanned}`;
|
|
9
|
+
//console.log(`controllerDir : ${controllerDir}`)
|
|
10
|
+
if(fs.existsSync(controllerDir)){
|
|
11
|
+
let cntrlFiles = this.getFiles(controllerDir);
|
|
12
|
+
//console.log(`cntrlFiles : ${cntrlFiles}`)
|
|
13
|
+
for(let i in cntrlFiles){
|
|
14
|
+
let cntrlFile = cntrlFiles[i];
|
|
15
|
+
let cntrlClass = require(cntrlFile);
|
|
16
|
+
if(typeof(Object.values(cntrlClass)[0]) === 'function')
|
|
17
|
+
config.register(Object.values(cntrlClass)[0]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getFiles (dir, files_?){
|
|
23
|
+
files_ = files_ || [];
|
|
24
|
+
var files;
|
|
25
|
+
try{
|
|
26
|
+
files = fs.readdirSync(dir);
|
|
27
|
+
}catch(err){
|
|
28
|
+
}
|
|
29
|
+
if(!files){
|
|
30
|
+
files = [];
|
|
31
|
+
}
|
|
32
|
+
for (var i in files){
|
|
33
|
+
let file = files[i];
|
|
34
|
+
var name = dir + '/' + file;
|
|
35
|
+
if (fs.statSync(name).isDirectory()){
|
|
36
|
+
this.getFiles(name, files_);
|
|
37
|
+
} else {
|
|
38
|
+
if(file.endsWith('.js'))
|
|
39
|
+
files_.push(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return files_;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export class ServiceContext {
|
|
2
|
+
serviceMap = {};
|
|
3
|
+
SchemaConfig = [];
|
|
4
|
+
commonService;
|
|
5
|
+
constructor(private app, private express, private authorizer?){}
|
|
6
|
+
register(controllerClass){
|
|
7
|
+
try{
|
|
8
|
+
//console.log(`registration of controllers ${controllerClass.name}`)
|
|
9
|
+
//console.log(`Controller metadata OLD: ${JSON.stringify(controllerClass.prototype)}`)
|
|
10
|
+
let controller = new controllerClass(this.app);
|
|
11
|
+
let cntrlMetadata = controllerClass.prototype;
|
|
12
|
+
let cntrlUri = cntrlMetadata.metadata?.baseUri;
|
|
13
|
+
|
|
14
|
+
if(cntrlUri){
|
|
15
|
+
//let controller = new controllerClass(app);
|
|
16
|
+
//console.log(`Controller metadata: ${controller.metadata}`)
|
|
17
|
+
//console.log(`Controller method metadata: ${JSON.stringify(controller['getDispensaryEmployees'])}`)
|
|
18
|
+
if(controller.metadata){
|
|
19
|
+
let router = this.express.Router();
|
|
20
|
+
this.serviceMap[controller.metadata.baseUri] = controller;
|
|
21
|
+
controller.request = this.request.bind(this);
|
|
22
|
+
if(!controller.router){
|
|
23
|
+
//console.log(`registration of controllers ${controller.metadata.baseUri}`)
|
|
24
|
+
if(controller.metadata.baseUri)
|
|
25
|
+
this.app.use(controller.metadata.baseUri, router);
|
|
26
|
+
controller.router = router;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
controller.getSchemaConfig = ()=>{
|
|
31
|
+
return this.SchemaConfig;
|
|
32
|
+
}
|
|
33
|
+
let schema = cntrlMetadata.metadata?.schema;
|
|
34
|
+
if(schema){
|
|
35
|
+
this.addSchemaConfig(schema);
|
|
36
|
+
}
|
|
37
|
+
//console.log(`Controller router: ${controller}`)
|
|
38
|
+
let protoOfTest = Object.getPrototypeOf(controller);
|
|
39
|
+
let methodMap = Object.getOwnPropertyNames(protoOfTest).filter(item=>!['constructor', 'metadata'].includes(item));
|
|
40
|
+
for(let idx=0; idx<methodMap.length; idx++){
|
|
41
|
+
let method = methodMap[idx];
|
|
42
|
+
if(schema){
|
|
43
|
+
this.addSchemaMethod(method, controller, schema);
|
|
44
|
+
}
|
|
45
|
+
if(schema?.id !== 'common'){
|
|
46
|
+
this.registerMethod(method, controller, controller.router);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//console.log('controller.metadata.baseUri '+controller.metadata?.baseUri);
|
|
50
|
+
//console.log('register Controller :: '+controller?.router?.stack);
|
|
51
|
+
if(schema?.id === 'common'){
|
|
52
|
+
this.commonService = controller;
|
|
53
|
+
}
|
|
54
|
+
}catch(err){
|
|
55
|
+
console.log('register Controller Error :: '+err.stack);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
addSchemaConfig(schema){
|
|
59
|
+
//console.log(`schema `, schema)
|
|
60
|
+
let idx = this.SchemaConfig.findIndex(item=>item?.id === schema.id);
|
|
61
|
+
if(idx === -1){
|
|
62
|
+
if(this.commonService){
|
|
63
|
+
schema.table = schema.table.concat(this.commonService.getSchemaConfig()[0].table)
|
|
64
|
+
}
|
|
65
|
+
this.SchemaConfig.push(schema);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
addPreProcessor(metadata, controller, schema){
|
|
69
|
+
let table = schema.table.find(item=>item?.id === metadata.uriMethod);
|
|
70
|
+
if(table){
|
|
71
|
+
if(!table.preProcessors)
|
|
72
|
+
table.preProcessors = []
|
|
73
|
+
table.preProcessors.push(controller[metadata.actualMethod].bind(controller));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
addPostProcessor(metadata, controller, schema){
|
|
77
|
+
let table = schema.table.find(item=>item?.id === metadata.uriMethod);
|
|
78
|
+
if(table){
|
|
79
|
+
if(!table.postProcessors)
|
|
80
|
+
table.postProcessors = []
|
|
81
|
+
table.postProcessors.push(controller[metadata.actualMethod].bind(controller));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
addSchemaMethod(method, controller, schema){
|
|
85
|
+
let metadata = controller[method].metadata;
|
|
86
|
+
//console.log('metadata ', metadata)
|
|
87
|
+
if(metadata?.isExecutor){
|
|
88
|
+
let idx = schema.table.findIndex(elem=>elem?.id === metadata.uriPath)
|
|
89
|
+
if(idx === -1){
|
|
90
|
+
//console.log('isExecutor')
|
|
91
|
+
schema.table.push({
|
|
92
|
+
id: metadata.uriPath.replace('/',''),
|
|
93
|
+
executor: controller[metadata.actualMethod].bind(controller)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if(metadata?.isPreProcessor){
|
|
98
|
+
this.addPreProcessor(metadata, controller, schema);
|
|
99
|
+
}
|
|
100
|
+
if(metadata?.isPostProcessor){
|
|
101
|
+
this.addPostProcessor(metadata, controller, schema);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
registerMethod(method, controller, router){
|
|
105
|
+
let metadata = controller[method].metadata;
|
|
106
|
+
//console.log('registerMethod :: '+method);
|
|
107
|
+
/*if(controllerClass.name === 'Master' && metadata){
|
|
108
|
+
console.log(`Controller method metadata: ${JSON.stringify(metadata)}`)
|
|
109
|
+
console.log(`Controller method metadata: ${controller[method]}`)
|
|
110
|
+
}*/
|
|
111
|
+
let secureCallback = this.authorizer;//Middleware.verifyToken.bind(Middleware);
|
|
112
|
+
if(metadata && router){
|
|
113
|
+
//console.log(`metadata `, metadata)
|
|
114
|
+
//console.log(`metadata.unsecured ${metadata.unsecured}`)
|
|
115
|
+
if(metadata.unsecured || !this.authorizer){
|
|
116
|
+
secureCallback = (req, res, next)=>{ next(); }
|
|
117
|
+
}
|
|
118
|
+
let callerMethod = (req, res, next)=>{
|
|
119
|
+
controller[method].apply(controller, [req, res, next]);
|
|
120
|
+
}
|
|
121
|
+
//let callerMethod = controller[method].bind(controller);
|
|
122
|
+
switch (metadata.uriMethod) {
|
|
123
|
+
case 'post':
|
|
124
|
+
router.post(metadata.uriPath, secureCallback, callerMethod);
|
|
125
|
+
break;
|
|
126
|
+
case 'put':
|
|
127
|
+
router.put(metadata.uriPath, secureCallback, callerMethod);
|
|
128
|
+
break;
|
|
129
|
+
case 'delete':
|
|
130
|
+
router.delete(metadata.uriPath, secureCallback, callerMethod);
|
|
131
|
+
break;
|
|
132
|
+
case 'get':
|
|
133
|
+
router.get(metadata.uriPath, secureCallback, callerMethod);
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
router.get(metadata.uriPath, secureCallback, callerMethod);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async request(options){
|
|
141
|
+
let uris = options.url.split('/');
|
|
142
|
+
let controller = this.serviceMap[`/${uris[1]}`];
|
|
143
|
+
let component;
|
|
144
|
+
let req:any = {
|
|
145
|
+
attributes: options.attributes,
|
|
146
|
+
body: options.body,
|
|
147
|
+
headers: options.headers,
|
|
148
|
+
method: options.method
|
|
149
|
+
};
|
|
150
|
+
if(!controller){
|
|
151
|
+
controller = this.serviceMap[`/`];
|
|
152
|
+
component = controller.router.stack.find(item=>item.route.path === `/:service/:operation`);
|
|
153
|
+
req.params = {service: uris[1], operation: uris[2]};
|
|
154
|
+
}
|
|
155
|
+
if(controller && !component){
|
|
156
|
+
component = controller.router.stack.find(item=>item.route.path === `/${uris[2]}`);
|
|
157
|
+
}
|
|
158
|
+
if(component){
|
|
159
|
+
req.path= component.route.path;
|
|
160
|
+
return new Promise((resolve, reject)=>{
|
|
161
|
+
let result = {
|
|
162
|
+
send: (data)=>{
|
|
163
|
+
resolve(data);
|
|
164
|
+
},
|
|
165
|
+
status: (status)=>{
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
component.handle(req, result);
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
return {status: 1};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import { ExpressLoader } from '../loader/express-loader';
|
|
2
|
+
|
|
1
3
|
export class Factory {
|
|
2
|
-
static async
|
|
3
|
-
let
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
static async getLinkConfig(){
|
|
7
|
-
let linkConfig = await import('../../lib/config/link-config');
|
|
8
|
-
return linkConfig.LinkConfig;
|
|
9
|
-
}
|
|
10
|
-
static async getApiService(){
|
|
11
|
-
let svc = await import('../../lib/dispatcher/health-service')
|
|
12
|
-
return svc.HealthService;
|
|
4
|
+
static async getLinkLoader(){
|
|
5
|
+
let svc = new ExpressLoader();
|
|
6
|
+
return svc;
|
|
13
7
|
}
|
|
14
8
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fileUpload from 'express-fileupload';
|
|
4
|
+
import cookieParser from "cookie-parser";
|
|
5
|
+
import sessions from 'express-session';
|
|
6
|
+
import bodyParser from 'body-parser';
|
|
7
|
+
import { AppLogger } from '../logger/app-logger';
|
|
8
|
+
import { ServiceContext } from '../container/service-context';
|
|
9
|
+
import { ExposeApi } from '../container/expose-api';
|
|
10
|
+
import { LinkConfig } from '../config/link-config';
|
|
11
|
+
import { LoadBalancer } from './load-balancer';
|
|
12
|
+
|
|
13
|
+
export class ExpressLoader {
|
|
14
|
+
app:any;
|
|
15
|
+
serverApp:any;
|
|
16
|
+
constructor(){
|
|
17
|
+
this.app = express();
|
|
18
|
+
this.app.use(bodyParser.json({
|
|
19
|
+
limit: '500mb'
|
|
20
|
+
}));
|
|
21
|
+
this.app.use(cookieParser());
|
|
22
|
+
this.app.use(bodyParser.urlencoded({
|
|
23
|
+
limit: '500mb',
|
|
24
|
+
parameterLimit: 100000,
|
|
25
|
+
extended: true
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
async init(config, appDir, serviceDir, callback){
|
|
29
|
+
let authType = config.authType || '0';
|
|
30
|
+
let threadPoolSize = config.threadPoolSize || 5;
|
|
31
|
+
let contextPath = config.baseUri;
|
|
32
|
+
this.app.use(sessions(config.SESSION_CONFIG));
|
|
33
|
+
this.app.use(fileUpload());
|
|
34
|
+
console.log('contextPath '+contextPath)
|
|
35
|
+
let router = express.Router();
|
|
36
|
+
let webDir = path.join(serviceDir, '../build');
|
|
37
|
+
router.use(express.static(webDir));
|
|
38
|
+
console.log(`IS_DEFAULT_AUTH :: ${authType}`)
|
|
39
|
+
console.log(`'0' === IS_DEFAULT_AUTH :: ${'0' === authType}`)
|
|
40
|
+
new AppLogger(config.CUSTOMER_ID, appDir);
|
|
41
|
+
if('0' === authType){
|
|
42
|
+
const { Middleware } = require('tharak-auth');
|
|
43
|
+
Middleware.setAppDir(`${serviceDir}/dummy/dummy`);
|
|
44
|
+
let dbProviderId = `${config.appName}_DbProvider`;
|
|
45
|
+
if(config.linkedDBItem && config.linkedDBItem.dbId){
|
|
46
|
+
LinkConfig.PROD_DB_CONFIGS[dbProviderId] = this.getDbOptions(config.linkedDBItem);
|
|
47
|
+
LinkConfig.DATABASE_PROVIDER = {id: config.linkedDBItem.dbId, configID : dbProviderId}
|
|
48
|
+
}
|
|
49
|
+
Middleware.setAppConfig(config);
|
|
50
|
+
this.serverApp = new ServiceContext(router, express, Middleware.verifyToken.bind(Middleware));
|
|
51
|
+
const { Login } = require('tharak-auth');
|
|
52
|
+
this.serverApp.register(Login);
|
|
53
|
+
Middleware.request = this.serverApp.request;
|
|
54
|
+
}else{
|
|
55
|
+
this.serverApp = new ServiceContext(router, express);
|
|
56
|
+
}
|
|
57
|
+
this.serverApp.register(await this.getCommonService());
|
|
58
|
+
this.serverApp.register(await this.getApiService());
|
|
59
|
+
new ExposeApi(config).registerControllers(serviceDir, this.serverApp);
|
|
60
|
+
/*let swaggerLinker = require('../swagger/swagger-linker');
|
|
61
|
+
swaggerLinker.init(contextPath, express);
|
|
62
|
+
swaggerLinker.use(this.app, '/doc');*/
|
|
63
|
+
this.app.use(contextPath, router);
|
|
64
|
+
let loadBalancer = new LoadBalancer(this.app);
|
|
65
|
+
var listenerPort = await loadBalancer.create(threadPoolSize, config.serverPort || 0);
|
|
66
|
+
console.log(`${contextPath} listening`);
|
|
67
|
+
console.log(`{"SERVER_PORT":${listenerPort}}`);
|
|
68
|
+
callback(listenerPort);
|
|
69
|
+
this.app.use((error, request, response, next)=>{
|
|
70
|
+
console.log(error.toString());
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
getDbOptions(linkedDB){
|
|
74
|
+
return {
|
|
75
|
+
user: linkedDB.dbUser,
|
|
76
|
+
password: linkedDB.dbPassword,
|
|
77
|
+
port: linkedDB.serverPort,
|
|
78
|
+
database: linkedDB.dbName,
|
|
79
|
+
server: linkedDB.serverName,
|
|
80
|
+
options: linkedDB.dbOptions,
|
|
81
|
+
pool: linkedDB.dbPoolConfig,
|
|
82
|
+
multipleStatements: linkedDB.dbMultipleStatements
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async getCommonService(){
|
|
86
|
+
let comm = await import('../../lib/database/schema/common-service')
|
|
87
|
+
return comm.CommonService;
|
|
88
|
+
}
|
|
89
|
+
async getApiService(){
|
|
90
|
+
let svc = await import('../../lib/dispatcher/health-service')
|
|
91
|
+
return svc.HealthService;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import httpProxy from 'nebula-http-proxy';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
export class LoadBalancer {
|
|
4
|
+
cur = 0;
|
|
5
|
+
servers = [];
|
|
6
|
+
numOfServers = 10;
|
|
7
|
+
proxyServer:any;
|
|
8
|
+
constructor(private app){
|
|
9
|
+
}
|
|
10
|
+
async create(threadPoolSize, serverPort){
|
|
11
|
+
return new Promise((resolve, reject)=>{
|
|
12
|
+
this.proxyServer = httpProxy.createProxyServer({
|
|
13
|
+
secure: false
|
|
14
|
+
});
|
|
15
|
+
if(threadPoolSize)
|
|
16
|
+
this.numOfServers = threadPoolSize;
|
|
17
|
+
this.load(this.numOfServers, this.app, this.servers);
|
|
18
|
+
let appRouteSvr:any = http.createServer({},this.createServer.bind(this)).listen(serverPort, () => {
|
|
19
|
+
|
|
20
|
+
resolve(appRouteSvr.address().port);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
private load(count, app, appSvrs){
|
|
25
|
+
for(let idx=0; idx<count; idx++){
|
|
26
|
+
let server = app.listen(0, ()=>{
|
|
27
|
+
appSvrs.push('http://localhost:'+server.address().port);
|
|
28
|
+
return console.log(`server is listening on ${server.address().port}`);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
private createServer(req, res){
|
|
33
|
+
try{
|
|
34
|
+
console.log('instance number :: '+this.cur);
|
|
35
|
+
let routeSvr = this.servers[this.cur];
|
|
36
|
+
console.log('Router '+routeSvr);
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
// Add any needed fields to
|
|
39
|
+
|
|
40
|
+
this.proxyServer.web(req, res, { target: routeSvr });
|
|
41
|
+
|
|
42
|
+
this.proxyServer.on('error', (err, errRq, errRs)=> {
|
|
43
|
+
console.log('Proxy error '+err.toString());
|
|
44
|
+
errRs.writeHead(500, {
|
|
45
|
+
'Content-Type': 'text/plain'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
errRs.end('Something went wrong. And we are reporting a custom error message.');
|
|
49
|
+
});
|
|
50
|
+
this.proxyServer.on('close', function (res, socket, head) {
|
|
51
|
+
// view disconnected websocket connections
|
|
52
|
+
console.log('Client disconnected');
|
|
53
|
+
});
|
|
54
|
+
this.cur = (this.cur + 1) % this.servers.length;
|
|
55
|
+
res.on('finish', () => {
|
|
56
|
+
console.log('Completed', req.method, req.url, Date.now() - start);
|
|
57
|
+
});
|
|
58
|
+
}catch(err){
|
|
59
|
+
console.log(err.toString())
|
|
60
|
+
res.status(500).send({
|
|
61
|
+
message: err.toString()
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import nodeLogger from 'nebula-node-logger';
|
|
3
|
+
export class AppLogger {
|
|
4
|
+
constructor(customerId, appLogDir?){
|
|
5
|
+
appLogDir = `./appLogs/`;
|
|
6
|
+
if(!fs.existsSync(appLogDir)){
|
|
7
|
+
fs.mkdirSync(appLogDir, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
const opts = {
|
|
10
|
+
errorEventName:'error',
|
|
11
|
+
logDirectory: appLogDir, // NOTE: folder must exist and be writable...
|
|
12
|
+
fileNamePattern:`${customerId}-<DATE>.log`,
|
|
13
|
+
dateFormat:'YYYY.MM.DD-HHa'
|
|
14
|
+
};
|
|
15
|
+
const log = nodeLogger.createRollingFileLogger( opts );
|
|
16
|
+
console.log = log.info;
|
|
17
|
+
console.error = log.error;
|
|
18
|
+
console.debug = log.debug;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/public-api.ts
CHANGED