@webtypen/webframez-core 0.0.55 → 0.0.57
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/lib/Router/Response.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { ServerResponse } from "http";
|
|
3
3
|
export declare class Response {
|
|
4
4
|
res?: ServerResponse;
|
|
5
5
|
statusCode: number;
|
|
@@ -49,5 +49,5 @@ export declare class Response {
|
|
|
49
49
|
* @param req
|
|
50
50
|
* @param payload
|
|
51
51
|
*/
|
|
52
|
-
handleEvents(eventKey: string, req:
|
|
52
|
+
handleEvents(eventKey: string, req: any, payload: any): Promise<void>;
|
|
53
53
|
}
|
package/lib/Router/Response.js
CHANGED
|
@@ -100,8 +100,8 @@ class Response {
|
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
for (let i in this.events[eventKey]) {
|
|
103
|
-
if (this.events[eventKey]
|
|
104
|
-
this.events[eventKey]
|
|
103
|
+
if (this.events[eventKey][i].function && typeof this.events[eventKey][i].function === "function") {
|
|
104
|
+
this.events[eventKey][i].function(req, payload);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
});
|
package/lib/Router/Router.js
CHANGED
|
@@ -294,7 +294,7 @@ class RouterFacade {
|
|
|
294
294
|
for (let middlewareKey of route.options.middleware) {
|
|
295
295
|
const middleware = this.kernel.middleware[middlewareKey];
|
|
296
296
|
if (!middleware) {
|
|
297
|
-
this.handleResponseAfter(response,
|
|
297
|
+
this.handleResponseAfter(response, request, { status: 500 });
|
|
298
298
|
if (this.mode === "aws-lambda") {
|
|
299
299
|
return {
|
|
300
300
|
statusCode: 500,
|
|
@@ -319,7 +319,7 @@ class RouterFacade {
|
|
|
319
319
|
}
|
|
320
320
|
catch (e) {
|
|
321
321
|
console.error(e);
|
|
322
|
-
this.handleResponseAfter(response,
|
|
322
|
+
this.handleResponseAfter(response, request, { status: 500 });
|
|
323
323
|
if (this.mode === "aws-lambda") {
|
|
324
324
|
return {
|
|
325
325
|
statusCode: 500,
|
|
@@ -338,7 +338,7 @@ class RouterFacade {
|
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
catch (e) {
|
|
341
|
-
this.handleResponseAfter(response,
|
|
341
|
+
this.handleResponseAfter(response, request, { status: 500, error: typeof e.data === "object" ? JSON.stringify(e.data) : e.data ? e.data : undefined });
|
|
342
342
|
// Send Middleware-Abort
|
|
343
343
|
if (this.mode === "aws-lambda") {
|
|
344
344
|
return {
|
|
@@ -377,7 +377,7 @@ class RouterFacade {
|
|
|
377
377
|
const split = route.component.split("@");
|
|
378
378
|
const controller = this.kernel.controller[split[0]];
|
|
379
379
|
if (!controller) {
|
|
380
|
-
this.handleResponseAfter(response,
|
|
380
|
+
this.handleResponseAfter(response, request, { status: 500, error: "Controller `" + split[0] + "` not found ..." });
|
|
381
381
|
if (this.mode === "aws-lambda") {
|
|
382
382
|
return {
|
|
383
383
|
statusCode: 500,
|
|
@@ -397,7 +397,7 @@ class RouterFacade {
|
|
|
397
397
|
// Set Controller method as route-component
|
|
398
398
|
const controllerInstance = new controller();
|
|
399
399
|
if (!controllerInstance || !split || !split[1] || !controllerInstance[split[1]]) {
|
|
400
|
-
this.handleResponseAfter(response,
|
|
400
|
+
this.handleResponseAfter(response, request, { status: 500, error: "controllerInstance `" + split[1] + "` not found ..." });
|
|
401
401
|
throw new Error("controllerInstance " + split[1] + " not found ...");
|
|
402
402
|
}
|
|
403
403
|
route.component = controllerInstance[split[1]].bind(controllerInstance);
|
|
@@ -405,7 +405,7 @@ class RouterFacade {
|
|
|
405
405
|
if (route && route.component !== undefined) {
|
|
406
406
|
try {
|
|
407
407
|
yield route.component(request, response);
|
|
408
|
-
this.handleResponseAfter(response,
|
|
408
|
+
this.handleResponseAfter(response, request, { status: response.statusCode });
|
|
409
409
|
if (this.mode === "aws-lambda") {
|
|
410
410
|
return {
|
|
411
411
|
statusCode: response.statusCode,
|
|
@@ -422,7 +422,7 @@ class RouterFacade {
|
|
|
422
422
|
if (process.env.APP_DEBUG_CONSOLE) {
|
|
423
423
|
console.error(e);
|
|
424
424
|
}
|
|
425
|
-
this.handleResponseAfter(response,
|
|
425
|
+
this.handleResponseAfter(response, request, { status: 500, error: e && e.stack && e.stack.toString().trim() !== '' ? e.stack : e && e.toString() !== '' ? e.toString() : "Error running the component ..." });
|
|
426
426
|
if (this.mode === "aws-lambda") {
|
|
427
427
|
return {
|
|
428
428
|
statusCode: 500,
|
|
@@ -441,7 +441,7 @@ class RouterFacade {
|
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
else {
|
|
444
|
-
this.handleResponseAfter(response,
|
|
444
|
+
this.handleResponseAfter(response, request, { status: 500, error: "Route component not found ..." });
|
|
445
445
|
if (this.mode === "aws-lambda") {
|
|
446
446
|
return {
|
|
447
447
|
statusCode: 500,
|
package/package.json
CHANGED
package/src/Router/Response.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServerResponse } from "http";
|
|
2
2
|
|
|
3
3
|
export class Response {
|
|
4
4
|
res?: ServerResponse;
|
|
@@ -94,14 +94,14 @@ export class Response {
|
|
|
94
94
|
* @param req
|
|
95
95
|
* @param payload
|
|
96
96
|
*/
|
|
97
|
-
async handleEvents(eventKey: string, req:
|
|
97
|
+
async handleEvents(eventKey: string, req: any, payload: any) {
|
|
98
98
|
if (!this.events || !this.events[eventKey] || this.events[eventKey].length < 1) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
for (let i in this.events[eventKey]) {
|
|
103
|
-
if (this.events[eventKey]
|
|
104
|
-
this.events[eventKey]
|
|
103
|
+
if (this.events[eventKey][i].function && typeof this.events[eventKey][i].function === "function") {
|
|
104
|
+
this.events[eventKey][i].function(req, payload);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
package/src/Router/Router.ts
CHANGED
|
@@ -335,7 +335,7 @@ class RouterFacade {
|
|
|
335
335
|
for (let middlewareKey of route.options.middleware) {
|
|
336
336
|
const middleware = this.kernel.middleware[middlewareKey];
|
|
337
337
|
if (!middleware) {
|
|
338
|
-
this.handleResponseAfter(response,
|
|
338
|
+
this.handleResponseAfter(response, request, { status: 500 });
|
|
339
339
|
|
|
340
340
|
if (this.mode === "aws-lambda") {
|
|
341
341
|
return {
|
|
@@ -366,7 +366,7 @@ class RouterFacade {
|
|
|
366
366
|
} catch (e) {
|
|
367
367
|
console.error(e);
|
|
368
368
|
|
|
369
|
-
this.handleResponseAfter(response,
|
|
369
|
+
this.handleResponseAfter(response, request, { status: 500 });
|
|
370
370
|
if (this.mode === "aws-lambda") {
|
|
371
371
|
return {
|
|
372
372
|
statusCode: 500,
|
|
@@ -383,7 +383,7 @@ class RouterFacade {
|
|
|
383
383
|
}
|
|
384
384
|
});
|
|
385
385
|
} catch (e: any) {
|
|
386
|
-
this.handleResponseAfter(response,
|
|
386
|
+
this.handleResponseAfter(response, request, { status: 500, error: typeof e.data === "object" ? JSON.stringify(e.data) : e.data ? e.data : undefined });
|
|
387
387
|
|
|
388
388
|
// Send Middleware-Abort
|
|
389
389
|
if (this.mode === "aws-lambda") {
|
|
@@ -426,7 +426,7 @@ class RouterFacade {
|
|
|
426
426
|
const split = route.component.split("@");
|
|
427
427
|
const controller = this.kernel.controller[split[0]];
|
|
428
428
|
if (!controller) {
|
|
429
|
-
this.handleResponseAfter(response,
|
|
429
|
+
this.handleResponseAfter(response, request, { status: 500, error: "Controller `" + split[0] + "` not found ..." });
|
|
430
430
|
|
|
431
431
|
if (this.mode === "aws-lambda") {
|
|
432
432
|
return {
|
|
@@ -447,7 +447,7 @@ class RouterFacade {
|
|
|
447
447
|
// Set Controller method as route-component
|
|
448
448
|
const controllerInstance = new controller();
|
|
449
449
|
if (!controllerInstance || !split || !split[1] || !controllerInstance[split[1]]) {
|
|
450
|
-
this.handleResponseAfter(response,
|
|
450
|
+
this.handleResponseAfter(response, request, { status: 500, error: "controllerInstance `" + split[1] + "` not found ..." });
|
|
451
451
|
throw new Error("controllerInstance " + split[1] + " not found ...");
|
|
452
452
|
}
|
|
453
453
|
route.component = controllerInstance[split[1]].bind(controllerInstance);
|
|
@@ -457,7 +457,7 @@ class RouterFacade {
|
|
|
457
457
|
try {
|
|
458
458
|
await route.component(request, response);
|
|
459
459
|
|
|
460
|
-
this.handleResponseAfter(response,
|
|
460
|
+
this.handleResponseAfter(response, request, { status: response.statusCode });
|
|
461
461
|
if (this.mode === "aws-lambda") {
|
|
462
462
|
return {
|
|
463
463
|
statusCode: response.statusCode,
|
|
@@ -473,7 +473,7 @@ class RouterFacade {
|
|
|
473
473
|
console.error(e);
|
|
474
474
|
}
|
|
475
475
|
|
|
476
|
-
this.handleResponseAfter(response,
|
|
476
|
+
this.handleResponseAfter(response, request, { status: 500, error: e && e.stack && e.stack.toString().trim() !== '' ? e.stack : e && e.toString() !== '' ? e.toString() : "Error running the component ..." });
|
|
477
477
|
if (this.mode === "aws-lambda") {
|
|
478
478
|
return {
|
|
479
479
|
statusCode: 500,
|
|
@@ -490,7 +490,7 @@ class RouterFacade {
|
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
492
|
} else {
|
|
493
|
-
this.handleResponseAfter(response,
|
|
493
|
+
this.handleResponseAfter(response, request, { status: 500, error: "Route component not found ..." });
|
|
494
494
|
if (this.mode === "aws-lambda") {
|
|
495
495
|
return {
|
|
496
496
|
statusCode: 500,
|