@webtypen/webframez-core 0.0.8 → 0.0.10

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.
@@ -90,6 +90,20 @@ class RouterFacade {
90
90
  else if (req.method === "DELETE") {
91
91
  return this.dissolveRoute(this.routesDELETE, req.url);
92
92
  }
93
+ else if (req.method === "OPTIONS") {
94
+ if (req.headers['access-control-request-method'] === 'GET') {
95
+ return this.dissolveRoute(this.routesGET, req.url);
96
+ }
97
+ else if (req.headers['access-control-request-method'] === 'POST') {
98
+ return this.dissolveRoute(this.routesPOST, req.url);
99
+ }
100
+ else if (req.headers['access-control-request-method'] === 'PUT') {
101
+ return this.dissolveRoute(this.routesPUT, req.url);
102
+ }
103
+ else if (req.headers['access-control-request-method'] === 'DELETE') {
104
+ return this.dissolveRoute(this.routesDELETE, req.url);
105
+ }
106
+ }
93
107
  return null;
94
108
  }
95
109
  /**
@@ -189,6 +203,13 @@ class RouterFacade {
189
203
  }
190
204
  }
191
205
  }
206
+ // Handle OPTIONS-Request
207
+ if (req.method === "OPTIONS") {
208
+ res.statusCode = 200;
209
+ res.setHeader('Content-Length', '0');
210
+ res.end();
211
+ return;
212
+ }
192
213
  // Resolve route-component (handle controller definition)
193
214
  if (route && typeof route.component === "string") {
194
215
  const split = route.component.split("@");
@@ -215,7 +236,13 @@ class RouterFacade {
215
236
  });
216
237
  try {
217
238
  yield route.component({
218
- body: bodyPlain ? qs_1.default.parse(bodyPlain) : {},
239
+ body: bodyPlain &&
240
+ req.headers["content-type"] === "application/json" &&
241
+ (bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
242
+ ? JSON.parse(bodyPlain)
243
+ : bodyPlain
244
+ ? qs_1.default.parse(bodyPlain)
245
+ : {},
219
246
  bodyPlain: bodyPlain,
220
247
  params: route.params,
221
248
  httpVersionMajor: req.httpVersionMajor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -112,6 +112,16 @@ class RouterFacade {
112
112
  return this.dissolveRoute(this.routesPUT, req.url);
113
113
  } else if (req.method === "DELETE") {
114
114
  return this.dissolveRoute(this.routesDELETE, req.url);
115
+ } else if (req.method === "OPTIONS") {
116
+ if (req.headers['access-control-request-method'] === 'GET') {
117
+ return this.dissolveRoute(this.routesGET, req.url);
118
+ } else if(req.headers['access-control-request-method'] === 'POST') {
119
+ return this.dissolveRoute(this.routesPOST, req.url);
120
+ } else if(req.headers['access-control-request-method'] === 'PUT') {
121
+ return this.dissolveRoute(this.routesPUT, req.url);
122
+ } else if(req.headers['access-control-request-method'] === 'DELETE') {
123
+ return this.dissolveRoute(this.routesDELETE, req.url);
124
+ }
115
125
  }
116
126
  return null;
117
127
  }
@@ -242,6 +252,14 @@ class RouterFacade {
242
252
  }
243
253
  }
244
254
 
255
+ // Handle OPTIONS-Request
256
+ if (req.method === "OPTIONS") {
257
+ res.statusCode = 200;
258
+ res.setHeader('Content-Length', '0');
259
+ res.end();
260
+ return;
261
+ }
262
+
245
263
  // Resolve route-component (handle controller definition)
246
264
  if (route && typeof route.component === "string") {
247
265
  const split = route.component.split("@");
@@ -272,7 +290,14 @@ class RouterFacade {
272
290
  try {
273
291
  await route.component(
274
292
  {
275
- body: bodyPlain ? qs.parse(bodyPlain) : {},
293
+ body:
294
+ bodyPlain &&
295
+ req.headers["content-type"] === "application/json" &&
296
+ (bodyPlain.trim().substring(0, 1) === "[" || bodyPlain.trim().substring(0, 1) === "{")
297
+ ? JSON.parse(bodyPlain)
298
+ : bodyPlain
299
+ ? qs.parse(bodyPlain)
300
+ : {},
276
301
  bodyPlain: bodyPlain,
277
302
  params: route.params,
278
303
  httpVersionMajor: req.httpVersionMajor,