@webtypen/webframez-core 0.0.27 → 0.0.28
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/LambdaApplication.d.ts +11 -0
- package/lib/LambdaApplication.js +24 -0
- package/lib/Router/Response.d.ts +7 -1
- package/lib/Router/Response.js +18 -4
- package/lib/Router/Router.d.ts +4 -0
- package/lib/Router/Router.js +6 -1
- package/lib/WebApplication.js +2 -2
- package/package.json +1 -1
- package/src/LambdaApplication.ts +26 -0
- package/src/Router/Response.ts +21 -4
- package/src/Router/Router.ts +7 -1
- package/src/WebApplication.ts +13 -13
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LambdaApplication = void 0;
|
|
4
|
+
const Config_1 = require("./Config");
|
|
5
|
+
const Router_1 = require("./Router/Router");
|
|
6
|
+
class LambdaApplication {
|
|
7
|
+
/**
|
|
8
|
+
* Init the routes and start the http-server
|
|
9
|
+
*/
|
|
10
|
+
boot(event, context, options) {
|
|
11
|
+
if (options && options.config) {
|
|
12
|
+
for (let key in options.config) {
|
|
13
|
+
Config_1.Config.register(key, options.config[key]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Router_1.Router.init({
|
|
17
|
+
mode: "aws-lambda",
|
|
18
|
+
kernel: options && options.kernel ? options.kernel : null,
|
|
19
|
+
basename: options && options.basename ? options.basename : null,
|
|
20
|
+
});
|
|
21
|
+
return { status: "success", mode: "lambda", event: event };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.LambdaApplication = LambdaApplication;
|
package/lib/Router/Response.d.ts
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
import { ServerResponse } from "http";
|
|
3
3
|
export declare class Response {
|
|
4
4
|
res?: ServerResponse;
|
|
5
|
+
content?: any | null | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Mode
|
|
8
|
+
*/
|
|
9
|
+
mode: any | null;
|
|
10
|
+
constructor(options?: any | null | undefined);
|
|
5
11
|
/**
|
|
6
12
|
* Sets the ServerResponse (res) Object (nodejs/http module)
|
|
7
13
|
* @param res
|
|
@@ -29,5 +35,5 @@ export declare class Response {
|
|
|
29
35
|
*
|
|
30
36
|
* @param content
|
|
31
37
|
*/
|
|
32
|
-
send(content: any):
|
|
38
|
+
send(content: any): this;
|
|
33
39
|
}
|
package/lib/Router/Response.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Response = void 0;
|
|
4
4
|
class Response {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
/**
|
|
7
|
+
* Mode
|
|
8
|
+
*/
|
|
9
|
+
this.mode = null;
|
|
10
|
+
this.mode = options && options.mode ? options.mode : null;
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Sets the ServerResponse (res) Object (nodejs/http module)
|
|
7
14
|
* @param res
|
|
@@ -46,13 +53,20 @@ class Response {
|
|
|
46
53
|
*/
|
|
47
54
|
send(content) {
|
|
48
55
|
var _a, _b, _c;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
this.content = content;
|
|
57
|
+
if (this.mode === "aws-lambda") {
|
|
58
|
+
// Do nothing ... Store content in variable and use it later ...
|
|
52
59
|
}
|
|
53
60
|
else {
|
|
54
|
-
(
|
|
61
|
+
if (typeof content === "object") {
|
|
62
|
+
(_a = this.res) === null || _a === void 0 ? void 0 : _a.setHeader("Content-Type", "application/json");
|
|
63
|
+
(_b = this.res) === null || _b === void 0 ? void 0 : _b.write(JSON.stringify(content));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
(_c = this.res) === null || _c === void 0 ? void 0 : _c.write(content);
|
|
67
|
+
}
|
|
55
68
|
}
|
|
69
|
+
return this;
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
72
|
exports.Response = Response;
|
package/lib/Router/Router.d.ts
CHANGED
package/lib/Router/Router.js
CHANGED
|
@@ -27,6 +27,10 @@ class RouterFacade {
|
|
|
27
27
|
* Kernel-Class
|
|
28
28
|
*/
|
|
29
29
|
this.kernel = null;
|
|
30
|
+
/**
|
|
31
|
+
* Mode
|
|
32
|
+
*/
|
|
33
|
+
this.mode = null;
|
|
30
34
|
/**
|
|
31
35
|
* GET Route Store
|
|
32
36
|
*/
|
|
@@ -51,6 +55,7 @@ class RouterFacade {
|
|
|
51
55
|
init(options) {
|
|
52
56
|
this.basename = options && options.basename ? options.basename : null;
|
|
53
57
|
this.kernel = options && options.kernel ? options.kernel : null;
|
|
58
|
+
this.mode = options && options.mode ? options.mode : null;
|
|
54
59
|
// Load routes
|
|
55
60
|
require(process.cwd() + "/app/routes");
|
|
56
61
|
}
|
|
@@ -181,7 +186,7 @@ class RouterFacade {
|
|
|
181
186
|
throw new Error("Missing Kernel in Router ...");
|
|
182
187
|
}
|
|
183
188
|
const route = this.dissolve(req);
|
|
184
|
-
const response = new Response_1.Response();
|
|
189
|
+
const response = new Response_1.Response({ mode: this.mode });
|
|
185
190
|
response.setServerResponse(res);
|
|
186
191
|
// Load Body
|
|
187
192
|
let body = [];
|
package/lib/WebApplication.js
CHANGED
|
@@ -18,12 +18,12 @@ class WebApplication {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
Router_1.Router.init({
|
|
21
|
+
mode: options.mode ? options.mode : null,
|
|
21
22
|
kernel: options && options.kernel ? options.kernel : null,
|
|
22
23
|
basename: options && options.basename ? options.basename : null,
|
|
23
24
|
});
|
|
24
25
|
const port = options && options.port ? options.port : 3000;
|
|
25
|
-
this.server = http_1.default
|
|
26
|
-
.createServer((req, res) => {
|
|
26
|
+
this.server = http_1.default.createServer((req, res) => {
|
|
27
27
|
Router_1.Router.handleRequest(req, res);
|
|
28
28
|
});
|
|
29
29
|
this.server.listen(port, () => {
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import http, { Server } from "http";
|
|
2
|
+
import { Config } from "./Config";
|
|
3
|
+
import { Router } from "./Router/Router";
|
|
4
|
+
|
|
5
|
+
export class LambdaApplication {
|
|
6
|
+
private server!: Server;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Init the routes and start the http-server
|
|
10
|
+
*/
|
|
11
|
+
boot(event: any, context: any, options?: any) {
|
|
12
|
+
if (options && options.config) {
|
|
13
|
+
for (let key in options.config) {
|
|
14
|
+
Config.register(key, options.config[key]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Router.init({
|
|
19
|
+
mode: "aws-lambda",
|
|
20
|
+
kernel: options && options.kernel ? options.kernel : null,
|
|
21
|
+
basename: options && options.basename ? options.basename : null,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return { status: "success", mode: "lambda", event: event };
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/Router/Response.ts
CHANGED
|
@@ -2,6 +2,16 @@ import { ServerResponse } from "http";
|
|
|
2
2
|
|
|
3
3
|
export class Response {
|
|
4
4
|
res?: ServerResponse;
|
|
5
|
+
content?: any | null | undefined;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mode
|
|
9
|
+
*/
|
|
10
|
+
mode: any | null = null;
|
|
11
|
+
|
|
12
|
+
constructor(options?: any | null | undefined) {
|
|
13
|
+
this.mode = options && options.mode ? options.mode : null;
|
|
14
|
+
}
|
|
5
15
|
|
|
6
16
|
/**
|
|
7
17
|
* Sets the ServerResponse (res) Object (nodejs/http module)
|
|
@@ -51,11 +61,18 @@ export class Response {
|
|
|
51
61
|
* @param content
|
|
52
62
|
*/
|
|
53
63
|
send(content: any) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
this.content = content;
|
|
65
|
+
|
|
66
|
+
if (this.mode === "aws-lambda") {
|
|
67
|
+
// Do nothing ... Store content in variable and use it later ...
|
|
57
68
|
} else {
|
|
58
|
-
|
|
69
|
+
if (typeof content === "object") {
|
|
70
|
+
this.res?.setHeader("Content-Type", "application/json");
|
|
71
|
+
this.res?.write(JSON.stringify(content));
|
|
72
|
+
} else {
|
|
73
|
+
this.res?.write(content);
|
|
74
|
+
}
|
|
59
75
|
}
|
|
76
|
+
return this;
|
|
60
77
|
}
|
|
61
78
|
}
|
package/src/Router/Router.ts
CHANGED
|
@@ -22,6 +22,11 @@ class RouterFacade {
|
|
|
22
22
|
*/
|
|
23
23
|
kernel: any | null = null;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Mode
|
|
27
|
+
*/
|
|
28
|
+
mode: any | null = null;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* GET Route Store
|
|
27
32
|
*/
|
|
@@ -77,6 +82,7 @@ class RouterFacade {
|
|
|
77
82
|
init(options?: any) {
|
|
78
83
|
this.basename = options && options.basename ? options.basename : null;
|
|
79
84
|
this.kernel = options && options.kernel ? options.kernel : null;
|
|
85
|
+
this.mode = options && options.mode ? options.mode : null;
|
|
80
86
|
|
|
81
87
|
// Load routes
|
|
82
88
|
require(process.cwd() + "/app/routes");
|
|
@@ -212,7 +218,7 @@ class RouterFacade {
|
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
const route = this.dissolve(req);
|
|
215
|
-
const response = new Response();
|
|
221
|
+
const response = new Response({ mode: this.mode });
|
|
216
222
|
response.setServerResponse(res);
|
|
217
223
|
|
|
218
224
|
// Load Body
|
package/src/WebApplication.ts
CHANGED
|
@@ -16,25 +16,25 @@ export class WebApplication {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
Router.init({
|
|
19
|
+
mode: options.mode ? options.mode : null,
|
|
19
20
|
kernel: options && options.kernel ? options.kernel : null,
|
|
20
21
|
basename: options && options.basename ? options.basename : null,
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
const port = options && options.port ? options.port : 3000;
|
|
24
|
-
this.server = http
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
this.server = http.createServer((req, res) => {
|
|
26
|
+
Router.handleRequest(req, res);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
29
|
this.server.listen(port, () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
console.log(
|
|
31
|
+
"Server started and listening on port " +
|
|
32
|
+
port +
|
|
33
|
+
(options && options.basename
|
|
34
|
+
? " (Basename: " + options && options.basename + ")"
|
|
35
|
+
: "")
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
38
|
return this.server;
|
|
39
39
|
}
|
|
40
40
|
}
|