@webtypen/webframez-core 0.0.16 → 0.0.17
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/Router.js +35 -33
- package/package.json +1 -1
- package/src/Router/Router.ts +38 -38
package/lib/Router/Router.js
CHANGED
|
@@ -177,12 +177,42 @@ class RouterFacade {
|
|
|
177
177
|
*/
|
|
178
178
|
handleRequest(req, res) {
|
|
179
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
const route = this.dissolve(req);
|
|
181
|
-
const response = new Response_1.Response();
|
|
182
|
-
response.setServerResponse(res);
|
|
183
180
|
if (!this.kernel) {
|
|
184
181
|
throw new Error("Missing Kernel in Router ...");
|
|
185
182
|
}
|
|
183
|
+
const route = this.dissolve(req);
|
|
184
|
+
const response = new Response_1.Response();
|
|
185
|
+
response.setServerResponse(res);
|
|
186
|
+
// Load Body
|
|
187
|
+
let body = [];
|
|
188
|
+
const bodyPlain = yield new Promise((resolve) => {
|
|
189
|
+
req
|
|
190
|
+
.on("data", (chunk) => {
|
|
191
|
+
body.push(chunk);
|
|
192
|
+
})
|
|
193
|
+
.on("end", () => {
|
|
194
|
+
resolve(Buffer.concat(body).toString());
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
const request = {
|
|
198
|
+
body: bodyPlain &&
|
|
199
|
+
req.headers["content-type"] === "application/json" &&
|
|
200
|
+
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
201
|
+
bodyPlain.trim().substring(0, 1) === "{")
|
|
202
|
+
? JSON.parse(bodyPlain)
|
|
203
|
+
: bodyPlain
|
|
204
|
+
? qs_1.default.parse(bodyPlain)
|
|
205
|
+
: {},
|
|
206
|
+
bodyPlain: bodyPlain,
|
|
207
|
+
params: route && route.params ? route.params : {},
|
|
208
|
+
httpVersionMajor: req.httpVersionMajor,
|
|
209
|
+
httpVersionMinor: req.httpVersionMinor,
|
|
210
|
+
httpVersion: req.httpVersion,
|
|
211
|
+
headers: req.headers,
|
|
212
|
+
rawHeaders: req.rawHeaders,
|
|
213
|
+
url: req.url,
|
|
214
|
+
method: req.method,
|
|
215
|
+
};
|
|
186
216
|
// Check-Middleware
|
|
187
217
|
if (route &&
|
|
188
218
|
route.options &&
|
|
@@ -198,7 +228,7 @@ class RouterFacade {
|
|
|
198
228
|
try {
|
|
199
229
|
middleware(resolve, (status, data) => {
|
|
200
230
|
reject({ status: status, data: data });
|
|
201
|
-
},
|
|
231
|
+
}, request, response);
|
|
202
232
|
}
|
|
203
233
|
catch (e) {
|
|
204
234
|
console.error(e);
|
|
@@ -241,36 +271,8 @@ class RouterFacade {
|
|
|
241
271
|
route.component = controllerInstance[split[1]];
|
|
242
272
|
}
|
|
243
273
|
if (route && route.component !== undefined) {
|
|
244
|
-
let body = [];
|
|
245
|
-
const bodyPlain = yield new Promise((resolve) => {
|
|
246
|
-
req
|
|
247
|
-
.on("data", (chunk) => {
|
|
248
|
-
body.push(chunk);
|
|
249
|
-
})
|
|
250
|
-
.on("end", () => {
|
|
251
|
-
resolve(Buffer.concat(body).toString());
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
274
|
try {
|
|
255
|
-
yield route.component(
|
|
256
|
-
body: bodyPlain &&
|
|
257
|
-
req.headers["content-type"] === "application/json" &&
|
|
258
|
-
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
259
|
-
bodyPlain.trim().substring(0, 1) === "{")
|
|
260
|
-
? JSON.parse(bodyPlain)
|
|
261
|
-
: bodyPlain
|
|
262
|
-
? qs_1.default.parse(bodyPlain)
|
|
263
|
-
: {},
|
|
264
|
-
bodyPlain: bodyPlain,
|
|
265
|
-
params: route.params,
|
|
266
|
-
httpVersionMajor: req.httpVersionMajor,
|
|
267
|
-
httpVersionMinor: req.httpVersionMinor,
|
|
268
|
-
httpVersion: req.httpVersion,
|
|
269
|
-
headers: req.headers,
|
|
270
|
-
rawHeaders: req.rawHeaders,
|
|
271
|
-
url: req.url,
|
|
272
|
-
method: req.method,
|
|
273
|
-
}, response);
|
|
275
|
+
yield route.component(request, response);
|
|
274
276
|
res.end();
|
|
275
277
|
}
|
|
276
278
|
catch (e) {
|
package/package.json
CHANGED
package/src/Router/Router.ts
CHANGED
|
@@ -207,13 +207,46 @@ class RouterFacade {
|
|
|
207
207
|
* @param res
|
|
208
208
|
*/
|
|
209
209
|
async handleRequest(req: IncomingMessage, res: ServerResponse) {
|
|
210
|
+
if (!this.kernel) {
|
|
211
|
+
throw new Error("Missing Kernel in Router ...");
|
|
212
|
+
}
|
|
213
|
+
|
|
210
214
|
const route = this.dissolve(req);
|
|
211
215
|
const response = new Response();
|
|
212
216
|
response.setServerResponse(res);
|
|
213
217
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
// Load Body
|
|
219
|
+
let body: any = [];
|
|
220
|
+
const bodyPlain: any = await new Promise((resolve: Function) => {
|
|
221
|
+
req
|
|
222
|
+
.on("data", (chunk) => {
|
|
223
|
+
body.push(chunk);
|
|
224
|
+
})
|
|
225
|
+
.on("end", () => {
|
|
226
|
+
resolve(Buffer.concat(body).toString());
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const request = {
|
|
231
|
+
body:
|
|
232
|
+
bodyPlain &&
|
|
233
|
+
req.headers["content-type"] === "application/json" &&
|
|
234
|
+
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
235
|
+
bodyPlain.trim().substring(0, 1) === "{")
|
|
236
|
+
? JSON.parse(bodyPlain)
|
|
237
|
+
: bodyPlain
|
|
238
|
+
? qs.parse(bodyPlain)
|
|
239
|
+
: {},
|
|
240
|
+
bodyPlain: bodyPlain,
|
|
241
|
+
params: route && route.params ? route.params : {},
|
|
242
|
+
httpVersionMajor: req.httpVersionMajor,
|
|
243
|
+
httpVersionMinor: req.httpVersionMinor,
|
|
244
|
+
httpVersion: req.httpVersion,
|
|
245
|
+
headers: req.headers,
|
|
246
|
+
rawHeaders: req.rawHeaders,
|
|
247
|
+
url: req.url,
|
|
248
|
+
method: req.method,
|
|
249
|
+
};
|
|
217
250
|
|
|
218
251
|
// Check-Middleware
|
|
219
252
|
if (
|
|
@@ -240,7 +273,7 @@ class RouterFacade {
|
|
|
240
273
|
(status: number, data: any) => {
|
|
241
274
|
reject({ status: status, data: data });
|
|
242
275
|
},
|
|
243
|
-
|
|
276
|
+
request,
|
|
244
277
|
response
|
|
245
278
|
);
|
|
246
279
|
} catch (e) {
|
|
@@ -297,41 +330,8 @@ class RouterFacade {
|
|
|
297
330
|
}
|
|
298
331
|
|
|
299
332
|
if (route && route.component !== undefined) {
|
|
300
|
-
let body: any = [];
|
|
301
|
-
const bodyPlain: any = await new Promise((resolve: Function) => {
|
|
302
|
-
req
|
|
303
|
-
.on("data", (chunk) => {
|
|
304
|
-
body.push(chunk);
|
|
305
|
-
})
|
|
306
|
-
.on("end", () => {
|
|
307
|
-
resolve(Buffer.concat(body).toString());
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
|
|
311
333
|
try {
|
|
312
|
-
await route.component(
|
|
313
|
-
{
|
|
314
|
-
body:
|
|
315
|
-
bodyPlain &&
|
|
316
|
-
req.headers["content-type"] === "application/json" &&
|
|
317
|
-
(bodyPlain.trim().substring(0, 1) === "[" ||
|
|
318
|
-
bodyPlain.trim().substring(0, 1) === "{")
|
|
319
|
-
? JSON.parse(bodyPlain)
|
|
320
|
-
: bodyPlain
|
|
321
|
-
? qs.parse(bodyPlain)
|
|
322
|
-
: {},
|
|
323
|
-
bodyPlain: bodyPlain,
|
|
324
|
-
params: route.params,
|
|
325
|
-
httpVersionMajor: req.httpVersionMajor,
|
|
326
|
-
httpVersionMinor: req.httpVersionMinor,
|
|
327
|
-
httpVersion: req.httpVersion,
|
|
328
|
-
headers: req.headers,
|
|
329
|
-
rawHeaders: req.rawHeaders,
|
|
330
|
-
url: req.url,
|
|
331
|
-
method: req.method,
|
|
332
|
-
},
|
|
333
|
-
response
|
|
334
|
-
);
|
|
334
|
+
await route.component(request, response);
|
|
335
335
|
res.end();
|
|
336
336
|
} catch (e) {
|
|
337
337
|
console.error(e);
|