@webtypen/webframez-core 0.0.60 → 0.0.62
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.d.ts +4 -0
- package/lib/Router/Router.js +15 -2
- package/package.json +1 -1
- package/src/Router/Router.ts +15 -2
package/lib/Router/Router.d.ts
CHANGED
|
@@ -100,6 +100,10 @@ declare class RouterFacade {
|
|
|
100
100
|
* @param res
|
|
101
101
|
*/
|
|
102
102
|
sendError(res: ServerResponse, code: number, message?: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Parses JSON without exception
|
|
105
|
+
*/
|
|
106
|
+
parseJson(jsonObject: any): any;
|
|
103
107
|
/**
|
|
104
108
|
* Processes a request
|
|
105
109
|
*
|
package/lib/Router/Router.js
CHANGED
|
@@ -188,6 +188,19 @@ class RouterFacade {
|
|
|
188
188
|
res.writeHead(code, { "Content-Type": "text/html" });
|
|
189
189
|
res.end(message ? message : code === 404 ? "Oops! Page not found ..." : "Oops! There was an unexpected error ...");
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Parses JSON without exception
|
|
193
|
+
*/
|
|
194
|
+
parseJson(jsonObject) {
|
|
195
|
+
let json = {};
|
|
196
|
+
try {
|
|
197
|
+
json = JSON.parse(jsonObject);
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
console.error(e);
|
|
201
|
+
}
|
|
202
|
+
return json;
|
|
203
|
+
}
|
|
191
204
|
/**
|
|
192
205
|
* Processes a request
|
|
193
206
|
*
|
|
@@ -254,7 +267,7 @@ class RouterFacade {
|
|
|
254
267
|
body: bodyPlain &&
|
|
255
268
|
customRequest.headers["content-type"] === "application/json" &&
|
|
256
269
|
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
257
|
-
?
|
|
270
|
+
? this.parseJson(bodyPlain)
|
|
258
271
|
: bodyPlain
|
|
259
272
|
? qs_1.default.parse(options && options.event && options.event.isBase64Encoded
|
|
260
273
|
? Buffer.from(bodyPlain, "base64").toString("utf-8")
|
|
@@ -274,7 +287,7 @@ class RouterFacade {
|
|
|
274
287
|
body: bodyPlain &&
|
|
275
288
|
req.headers["content-type"] === "application/json" &&
|
|
276
289
|
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
277
|
-
?
|
|
290
|
+
? this.parseJson(bodyPlain)
|
|
278
291
|
: bodyPlain
|
|
279
292
|
? qs_1.default.parse(bodyPlain)
|
|
280
293
|
: {},
|
package/package.json
CHANGED
package/src/Router/Router.ts
CHANGED
|
@@ -218,6 +218,19 @@ class RouterFacade {
|
|
|
218
218
|
res.end(message ? message : code === 404 ? "Oops! Page not found ..." : "Oops! There was an unexpected error ...");
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Parses JSON without exception
|
|
223
|
+
*/
|
|
224
|
+
parseJson(jsonObject: any) {
|
|
225
|
+
let json: any = {};
|
|
226
|
+
try {
|
|
227
|
+
json = JSON.parse(jsonObject);
|
|
228
|
+
} catch(e: any) {
|
|
229
|
+
console.error(e);
|
|
230
|
+
}
|
|
231
|
+
return json;
|
|
232
|
+
}
|
|
233
|
+
|
|
221
234
|
/**
|
|
222
235
|
* Processes a request
|
|
223
236
|
*
|
|
@@ -291,7 +304,7 @@ class RouterFacade {
|
|
|
291
304
|
bodyPlain &&
|
|
292
305
|
customRequest.headers["content-type"] === "application/json" &&
|
|
293
306
|
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
294
|
-
?
|
|
307
|
+
? this.parseJson(bodyPlain)
|
|
295
308
|
: bodyPlain
|
|
296
309
|
? qs.parse(
|
|
297
310
|
options && options.event && options.event.isBase64Encoded
|
|
@@ -314,7 +327,7 @@ class RouterFacade {
|
|
|
314
327
|
bodyPlain &&
|
|
315
328
|
req.headers["content-type"] === "application/json" &&
|
|
316
329
|
(bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
|
|
317
|
-
?
|
|
330
|
+
? this.parseJson(bodyPlain)
|
|
318
331
|
: bodyPlain
|
|
319
332
|
? qs.parse(bodyPlain)
|
|
320
333
|
: {},
|