@webtypen/webframez-core 0.0.52 → 0.0.53
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/.prettierrc +1 -1
- package/lib/Router/Route.js +14 -32
- package/lib/Router/Router.js +25 -33
- package/lib/WebApplication.js +2 -4
- package/package.json +1 -1
- package/src/Router/Route.ts +127 -145
- package/src/Router/Router.ts +507 -542
- package/src/WebApplication.ts +28 -30
package/.prettierrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "printWidth": 140 }
|
|
1
|
+
{ "printWidth": 140, "tabWidth": 4 }
|
package/lib/Router/Route.js
CHANGED
|
@@ -18,12 +18,8 @@ class RouteFacade {
|
|
|
18
18
|
Router_1.Router.register("GET", (this.tempGroupPrefix ? this.tempGroupPrefix : "") + path, component, options || this.tempGroupMiddleware
|
|
19
19
|
? Object.assign(Object.assign({}, (options ? options : {})), { middleware: this.tempGroupMiddleware || (options && options.middleware)
|
|
20
20
|
? [
|
|
21
|
-
...(this.tempGroupMiddleware
|
|
22
|
-
|
|
23
|
-
: []),
|
|
24
|
-
...(options && options.middleware
|
|
25
|
-
? options.middleware
|
|
26
|
-
: []),
|
|
21
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
22
|
+
...(options && options.middleware ? options.middleware : []),
|
|
27
23
|
]
|
|
28
24
|
: null }) : {});
|
|
29
25
|
}
|
|
@@ -38,12 +34,8 @@ class RouteFacade {
|
|
|
38
34
|
Router_1.Router.register("POST", (this.tempGroupPrefix ? this.tempGroupPrefix : "") + path, component, options || this.tempGroupMiddleware
|
|
39
35
|
? Object.assign(Object.assign({}, (options ? options : {})), { middleware: this.tempGroupMiddleware || (options && options.middleware)
|
|
40
36
|
? [
|
|
41
|
-
...(this.tempGroupMiddleware
|
|
42
|
-
|
|
43
|
-
: []),
|
|
44
|
-
...(options && options.middleware
|
|
45
|
-
? options.middleware
|
|
46
|
-
: []),
|
|
37
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
38
|
+
...(options && options.middleware ? options.middleware : []),
|
|
47
39
|
]
|
|
48
40
|
: null }) : {});
|
|
49
41
|
}
|
|
@@ -58,12 +50,8 @@ class RouteFacade {
|
|
|
58
50
|
Router_1.Router.register("PUT", (this.tempGroupPrefix ? this.tempGroupPrefix : "") + path, component, options || this.tempGroupMiddleware
|
|
59
51
|
? Object.assign(Object.assign({}, (options ? options : {})), { middleware: this.tempGroupMiddleware || (options && options.middleware)
|
|
60
52
|
? [
|
|
61
|
-
...(this.tempGroupMiddleware
|
|
62
|
-
|
|
63
|
-
: []),
|
|
64
|
-
...(options && options.middleware
|
|
65
|
-
? options.middleware
|
|
66
|
-
: []),
|
|
53
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
54
|
+
...(options && options.middleware ? options.middleware : []),
|
|
67
55
|
]
|
|
68
56
|
: null }) : {});
|
|
69
57
|
}
|
|
@@ -78,20 +66,17 @@ class RouteFacade {
|
|
|
78
66
|
Router_1.Router.register("DELETE", (this.tempGroupPrefix ? this.tempGroupPrefix : "") + path, component, options || this.tempGroupMiddleware
|
|
79
67
|
? Object.assign(Object.assign({}, (options ? options : {})), { middleware: this.tempGroupMiddleware || (options && options.middleware)
|
|
80
68
|
? [
|
|
81
|
-
...(this.tempGroupMiddleware
|
|
82
|
-
|
|
83
|
-
: []),
|
|
84
|
-
...(options && options.middleware
|
|
85
|
-
? options.middleware
|
|
86
|
-
: []),
|
|
69
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
70
|
+
...(options && options.middleware ? options.middleware : []),
|
|
87
71
|
]
|
|
88
72
|
: null }) : {});
|
|
89
73
|
}
|
|
90
74
|
group(config, children) {
|
|
91
75
|
// Handle group prefix
|
|
76
|
+
const tempGroupPrefixBefore = this.tempGroupPrefix ? this.tempGroupPrefix + "" : null;
|
|
77
|
+
const tempGroupMiddlewareBefore = this.tempGroupMiddleware && this.tempGroupMiddleware.length > 0 ? this.tempGroupMiddleware : null;
|
|
92
78
|
if (config && config.prefix && config.prefix.trim() !== "") {
|
|
93
|
-
this.tempGroupPrefix =
|
|
94
|
-
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + config.prefix;
|
|
79
|
+
this.tempGroupPrefix = (this.tempGroupPrefix ? this.tempGroupPrefix : "") + config.prefix;
|
|
95
80
|
}
|
|
96
81
|
// Handle group middleware
|
|
97
82
|
if (config && config.middleware && config.middleware.length > 0) {
|
|
@@ -99,17 +84,14 @@ class RouteFacade {
|
|
|
99
84
|
this.tempGroupMiddleware = config.middleware;
|
|
100
85
|
}
|
|
101
86
|
else {
|
|
102
|
-
this.tempGroupMiddleware = [
|
|
103
|
-
...this.tempGroupMiddleware,
|
|
104
|
-
...config.middleware,
|
|
105
|
-
];
|
|
87
|
+
this.tempGroupMiddleware = [...this.tempGroupMiddleware, ...config.middleware];
|
|
106
88
|
}
|
|
107
89
|
}
|
|
108
90
|
// Handle children / group body
|
|
109
91
|
children();
|
|
110
92
|
// Reset temp-group data
|
|
111
|
-
this.tempGroupPrefix =
|
|
112
|
-
this.tempGroupMiddleware =
|
|
93
|
+
this.tempGroupPrefix = tempGroupPrefixBefore;
|
|
94
|
+
this.tempGroupMiddleware = tempGroupMiddlewareBefore;
|
|
113
95
|
}
|
|
114
96
|
}
|
|
115
97
|
exports.RouteFacade = RouteFacade;
|
package/lib/Router/Router.js
CHANGED
|
@@ -85,6 +85,20 @@ class RouterFacade {
|
|
|
85
85
|
options: options,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
+
else if (type === "PUT") {
|
|
89
|
+
this.routesPUT[path] = {
|
|
90
|
+
path: path,
|
|
91
|
+
component: component,
|
|
92
|
+
options: options,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else if (type === "DELETE") {
|
|
96
|
+
this.routesDELETE[path] = {
|
|
97
|
+
path: path,
|
|
98
|
+
component: component,
|
|
99
|
+
options: options,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
88
102
|
}
|
|
89
103
|
/**
|
|
90
104
|
* Loads the matching route based on the request-url
|
|
@@ -172,11 +186,7 @@ class RouterFacade {
|
|
|
172
186
|
*/
|
|
173
187
|
sendError(res, code, message) {
|
|
174
188
|
res.writeHead(code, { "Content-Type": "text/html" });
|
|
175
|
-
res.end(message
|
|
176
|
-
? message
|
|
177
|
-
: code === 404
|
|
178
|
-
? "Oops! Page not found ..."
|
|
179
|
-
: "Oops! There was an unexpected error ...");
|
|
189
|
+
res.end(message ? message : code === 404 ? "Oops! Page not found ..." : "Oops! There was an unexpected error ...");
|
|
180
190
|
}
|
|
181
191
|
/**
|
|
182
192
|
* Processes a request
|
|
@@ -191,9 +201,7 @@ class RouterFacade {
|
|
|
191
201
|
customRequest = {
|
|
192
202
|
method: options.event.requestContext.http.method,
|
|
193
203
|
url: options.event.rawPath +
|
|
194
|
-
(options.event.rawQueryString && options.event.rawQueryString.trim() !==
|
|
195
|
-
"?" + options.event.rawQueryString
|
|
196
|
-
: ""),
|
|
204
|
+
(options.event.rawQueryString && options.event.rawQueryString.trim() !== "" ? "?" + options.event.rawQueryString : ""),
|
|
197
205
|
headers: options.event.headers,
|
|
198
206
|
urlParams: options.event.queryStringParameters ? options.event.queryStringParameters : {},
|
|
199
207
|
};
|
|
@@ -217,11 +225,9 @@ class RouterFacade {
|
|
|
217
225
|
: null
|
|
218
226
|
: req
|
|
219
227
|
? yield new Promise((resolve) => {
|
|
220
|
-
req
|
|
221
|
-
.on("data", (chunk) => {
|
|
228
|
+
req.on("data", (chunk) => {
|
|
222
229
|
body.push(chunk);
|
|
223
|
-
})
|
|
224
|
-
.on("end", () => {
|
|
230
|
+
}).on("end", () => {
|
|
225
231
|
resolve(Buffer.concat(body).toString());
|
|
226
232
|
});
|
|
227
233
|
})
|
|
@@ -247,8 +253,7 @@ class RouterFacade {
|
|
|
247
253
|
? {
|
|
248
254
|
body: bodyPlain &&
|
|
249
255
|
customRequest.headers["content-type"] === "application/json" &&
|
|
250
|
-
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
251
|
-
bodyPlain.trim().substring(0, 1) === "{")
|
|
256
|
+
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
252
257
|
? JSON.parse(bodyPlain)
|
|
253
258
|
: bodyPlain
|
|
254
259
|
? qs_1.default.parse(options && options.event && options.event.isBase64Encoded
|
|
@@ -266,8 +271,7 @@ class RouterFacade {
|
|
|
266
271
|
? {
|
|
267
272
|
body: bodyPlain &&
|
|
268
273
|
req.headers["content-type"] === "application/json" &&
|
|
269
|
-
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
270
|
-
bodyPlain.trim().substring(0, 1) === "{")
|
|
274
|
+
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
271
275
|
? JSON.parse(bodyPlain)
|
|
272
276
|
: bodyPlain
|
|
273
277
|
? qs_1.default.parse(bodyPlain)
|
|
@@ -286,10 +290,7 @@ class RouterFacade {
|
|
|
286
290
|
}
|
|
287
291
|
: null;
|
|
288
292
|
// Check-Middleware
|
|
289
|
-
if (route &&
|
|
290
|
-
route.options &&
|
|
291
|
-
route.options.middleware &&
|
|
292
|
-
route.options.middleware.length > 0) {
|
|
293
|
+
if (route && route.options && route.options.middleware && route.options.middleware.length > 0) {
|
|
293
294
|
for (let middlewareKey of route.options.middleware) {
|
|
294
295
|
const middleware = this.kernel.middleware[middlewareKey];
|
|
295
296
|
if (!middleware) {
|
|
@@ -344,14 +345,8 @@ class RouterFacade {
|
|
|
344
345
|
};
|
|
345
346
|
}
|
|
346
347
|
else if (res) {
|
|
347
|
-
res.writeHead(e.status, typeof e.data === "object"
|
|
348
|
-
|
|
349
|
-
: { "Content-Type": "text/html" });
|
|
350
|
-
res.end(typeof e.data === "object"
|
|
351
|
-
? JSON.stringify(e.data)
|
|
352
|
-
: e.data
|
|
353
|
-
? e.data
|
|
354
|
-
: " ");
|
|
348
|
+
res.writeHead(e.status, typeof e.data === "object" ? { "Content-Type": "application/json" } : { "Content-Type": "text/html" });
|
|
349
|
+
res.end(typeof e.data === "object" ? JSON.stringify(e.data) : e.data ? e.data : " ");
|
|
355
350
|
}
|
|
356
351
|
return;
|
|
357
352
|
}
|
|
@@ -454,8 +449,7 @@ class RouterFacade {
|
|
|
454
449
|
});
|
|
455
450
|
}
|
|
456
451
|
requestConsoleLog(req, httpCode) {
|
|
457
|
-
if (Config_1.Config.get("application.router.requests.logConsole") !== true &&
|
|
458
|
-
!Config_1.Config.get("application.router.requests.logFile")) {
|
|
452
|
+
if (Config_1.Config.get("application.router.requests.logConsole") !== true && !Config_1.Config.get("application.router.requests.logFile")) {
|
|
459
453
|
return;
|
|
460
454
|
}
|
|
461
455
|
const date = new Date();
|
|
@@ -497,9 +491,7 @@ class RouterFacade {
|
|
|
497
491
|
try {
|
|
498
492
|
const filepath = Config_1.Config.get("application.router.requests.logFile");
|
|
499
493
|
if (filepath && filepath.trim() !== "") {
|
|
500
|
-
fs_1.default.appendFileSync(filepath.trim().substring(0, 1) === "/"
|
|
501
|
-
? filepath
|
|
502
|
-
: process.cwd() + "/" + filepath, logString + "\n");
|
|
494
|
+
fs_1.default.appendFileSync(filepath.trim().substring(0, 1) === "/" ? filepath : process.cwd() + "/" + filepath, logString + "\n");
|
|
503
495
|
}
|
|
504
496
|
}
|
|
505
497
|
catch (e) {
|
package/lib/WebApplication.js
CHANGED
|
@@ -18,7 +18,7 @@ class WebApplication {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
Router_1.Router.init({
|
|
21
|
-
mode: options.mode ? options.mode : null,
|
|
21
|
+
mode: options && options.mode ? options.mode : null,
|
|
22
22
|
kernel: options && options.kernel ? options.kernel : null,
|
|
23
23
|
basename: options && options.basename ? options.basename : null,
|
|
24
24
|
});
|
|
@@ -29,9 +29,7 @@ class WebApplication {
|
|
|
29
29
|
this.server.listen(port, () => {
|
|
30
30
|
console.log("Server started and listening on port " +
|
|
31
31
|
port +
|
|
32
|
-
(options && options.basename
|
|
33
|
-
? " (Basename: " + options && options.basename + ")"
|
|
34
|
-
: ""));
|
|
32
|
+
(options && options.basename ? " (Basename: " + options && options.basename + ")" : ""));
|
|
35
33
|
});
|
|
36
34
|
return this.server;
|
|
37
35
|
}
|
package/package.json
CHANGED
package/src/Router/Route.ts
CHANGED
|
@@ -1,159 +1,141 @@
|
|
|
1
1
|
import { Router } from "./Router";
|
|
2
2
|
|
|
3
3
|
export class RouteFacade {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
tempGroupPrefix: string | null = null;
|
|
5
|
+
tempGroupMiddleware: string[] | null = null;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
: {}
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Register a POST-Method
|
|
40
|
-
*
|
|
41
|
-
* @param path
|
|
42
|
-
* @param component
|
|
43
|
-
* @param options
|
|
44
|
-
*/
|
|
45
|
-
post(path: string, component: any, options?: { [key: string]: any }) {
|
|
46
|
-
Router.register(
|
|
47
|
-
"POST",
|
|
48
|
-
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
49
|
-
component,
|
|
50
|
-
options || this.tempGroupMiddleware
|
|
51
|
-
? {
|
|
52
|
-
...(options ? options : {}),
|
|
53
|
-
middleware:
|
|
54
|
-
this.tempGroupMiddleware || (options && options.middleware)
|
|
55
|
-
? [
|
|
56
|
-
...(this.tempGroupMiddleware
|
|
57
|
-
? this.tempGroupMiddleware
|
|
58
|
-
: []),
|
|
59
|
-
...(options && options.middleware
|
|
60
|
-
? options.middleware
|
|
61
|
-
: []),
|
|
62
|
-
]
|
|
63
|
-
: null,
|
|
64
|
-
}
|
|
65
|
-
: {}
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Register a PUT-Method
|
|
71
|
-
*
|
|
72
|
-
* @param path
|
|
73
|
-
* @param component
|
|
74
|
-
* @param options
|
|
75
|
-
*/
|
|
76
|
-
put(path: string, component: any, options?: { [key: string]: any }) {
|
|
77
|
-
Router.register(
|
|
78
|
-
"PUT",
|
|
79
|
-
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
80
|
-
component,
|
|
81
|
-
options || this.tempGroupMiddleware
|
|
82
|
-
? {
|
|
83
|
-
...(options ? options : {}),
|
|
84
|
-
middleware:
|
|
85
|
-
this.tempGroupMiddleware || (options && options.middleware)
|
|
86
|
-
? [
|
|
87
|
-
...(this.tempGroupMiddleware
|
|
88
|
-
? this.tempGroupMiddleware
|
|
89
|
-
: []),
|
|
90
|
-
...(options && options.middleware
|
|
91
|
-
? options.middleware
|
|
92
|
-
: []),
|
|
93
|
-
]
|
|
94
|
-
: null,
|
|
95
|
-
}
|
|
96
|
-
: {}
|
|
97
|
-
);
|
|
98
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* Register a GET-Method
|
|
9
|
+
*
|
|
10
|
+
* @param path
|
|
11
|
+
* @param component
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
get(path: string, component: any, options?: { [key: string]: any }) {
|
|
15
|
+
Router.register(
|
|
16
|
+
"GET",
|
|
17
|
+
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
18
|
+
component,
|
|
19
|
+
options || this.tempGroupMiddleware
|
|
20
|
+
? {
|
|
21
|
+
...(options ? options : {}),
|
|
22
|
+
middleware:
|
|
23
|
+
this.tempGroupMiddleware || (options && options.middleware)
|
|
24
|
+
? [
|
|
25
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
26
|
+
...(options && options.middleware ? options.middleware : []),
|
|
27
|
+
]
|
|
28
|
+
: null,
|
|
29
|
+
}
|
|
30
|
+
: {}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
99
33
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
: {}
|
|
128
|
-
);
|
|
129
|
-
}
|
|
34
|
+
/**
|
|
35
|
+
* Register a POST-Method
|
|
36
|
+
*
|
|
37
|
+
* @param path
|
|
38
|
+
* @param component
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
41
|
+
post(path: string, component: any, options?: { [key: string]: any }) {
|
|
42
|
+
Router.register(
|
|
43
|
+
"POST",
|
|
44
|
+
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
45
|
+
component,
|
|
46
|
+
options || this.tempGroupMiddleware
|
|
47
|
+
? {
|
|
48
|
+
...(options ? options : {}),
|
|
49
|
+
middleware:
|
|
50
|
+
this.tempGroupMiddleware || (options && options.middleware)
|
|
51
|
+
? [
|
|
52
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
53
|
+
...(options && options.middleware ? options.middleware : []),
|
|
54
|
+
]
|
|
55
|
+
: null,
|
|
56
|
+
}
|
|
57
|
+
: {}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
130
60
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Register a PUT-Method
|
|
63
|
+
*
|
|
64
|
+
* @param path
|
|
65
|
+
* @param component
|
|
66
|
+
* @param options
|
|
67
|
+
*/
|
|
68
|
+
put(path: string, component: any, options?: { [key: string]: any }) {
|
|
69
|
+
Router.register(
|
|
70
|
+
"PUT",
|
|
71
|
+
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
72
|
+
component,
|
|
73
|
+
options || this.tempGroupMiddleware
|
|
74
|
+
? {
|
|
75
|
+
...(options ? options : {}),
|
|
76
|
+
middleware:
|
|
77
|
+
this.tempGroupMiddleware || (options && options.middleware)
|
|
78
|
+
? [
|
|
79
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
80
|
+
...(options && options.middleware ? options.middleware : []),
|
|
81
|
+
]
|
|
82
|
+
: null,
|
|
83
|
+
}
|
|
84
|
+
: {}
|
|
85
|
+
);
|
|
136
86
|
}
|
|
137
87
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Register a DELETE-Method
|
|
90
|
+
*
|
|
91
|
+
* @param path
|
|
92
|
+
* @param component
|
|
93
|
+
* @param options
|
|
94
|
+
*/
|
|
95
|
+
delete(path: string, component: any, options?: { [key: string]: any }) {
|
|
96
|
+
Router.register(
|
|
97
|
+
"DELETE",
|
|
98
|
+
(this.tempGroupPrefix ? this.tempGroupPrefix : "") + path,
|
|
99
|
+
component,
|
|
100
|
+
options || this.tempGroupMiddleware
|
|
101
|
+
? {
|
|
102
|
+
...(options ? options : {}),
|
|
103
|
+
middleware:
|
|
104
|
+
this.tempGroupMiddleware || (options && options.middleware)
|
|
105
|
+
? [
|
|
106
|
+
...(this.tempGroupMiddleware ? this.tempGroupMiddleware : []),
|
|
107
|
+
...(options && options.middleware ? options.middleware : []),
|
|
108
|
+
]
|
|
109
|
+
: null,
|
|
110
|
+
}
|
|
111
|
+
: {}
|
|
112
|
+
);
|
|
148
113
|
}
|
|
149
114
|
|
|
150
|
-
|
|
151
|
-
|
|
115
|
+
group(config: { [key: string]: any }, children: any) {
|
|
116
|
+
// Handle group prefix
|
|
117
|
+
const tempGroupPrefixBefore = this.tempGroupPrefix ? this.tempGroupPrefix + "" : null;
|
|
118
|
+
const tempGroupMiddlewareBefore = this.tempGroupMiddleware && this.tempGroupMiddleware.length > 0 ? this.tempGroupMiddleware : null;
|
|
119
|
+
if (config && config.prefix && config.prefix.trim() !== "") {
|
|
120
|
+
this.tempGroupPrefix = (this.tempGroupPrefix ? this.tempGroupPrefix : "") + config.prefix;
|
|
121
|
+
}
|
|
152
122
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
123
|
+
// Handle group middleware
|
|
124
|
+
if (config && config.middleware && config.middleware.length > 0) {
|
|
125
|
+
if (!this.tempGroupMiddleware || this.tempGroupMiddleware.length === 0) {
|
|
126
|
+
this.tempGroupMiddleware = config.middleware;
|
|
127
|
+
} else {
|
|
128
|
+
this.tempGroupMiddleware = [...this.tempGroupMiddleware, ...config.middleware];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Handle children / group body
|
|
133
|
+
children();
|
|
134
|
+
|
|
135
|
+
// Reset temp-group data
|
|
136
|
+
this.tempGroupPrefix = tempGroupPrefixBefore;
|
|
137
|
+
this.tempGroupMiddleware = tempGroupMiddlewareBefore;
|
|
138
|
+
}
|
|
157
139
|
}
|
|
158
140
|
|
|
159
141
|
export const Route = new RouteFacade();
|