@nattyjs/express 0.0.1-beta.30 → 0.0.1-beta.32

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/dist/index.cjs CHANGED
@@ -15,18 +15,18 @@ const compression__default = /*#__PURE__*/_interopDefaultCompat(compression);
15
15
  async function getRequestBodyInfo(request) {
16
16
  const contentType = request.headers["content-type"];
17
17
  const bodyInfo = {};
18
- if (request.method !== common.GET)
19
- switch (contentType) {
20
- case "application/json":
21
- bodyInfo.json = request.body;
22
- break;
23
- }
18
+ if (request.method !== common.GET) {
19
+ if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
20
+ bodyInfo.json = request.body;
21
+ }
24
22
  return bodyInfo;
25
23
  }
26
24
 
27
25
  function getResponse(expressResponse, responseInfo) {
28
26
  if (responseInfo.headers)
29
- Object.keys(responseInfo.headers).forEach((key) => expressResponse.set(key, responseInfo.headers[key]));
27
+ for (const pair of responseInfo.headers.entries()) {
28
+ expressResponse.setHeader(pair[0], pair[1]);
29
+ }
30
30
  if (responseInfo.cookies)
31
31
  responseInfo.cookies.forEach((cookie) => {
32
32
  const name = cookie.name;
@@ -38,7 +38,9 @@ function getResponse(expressResponse, responseInfo) {
38
38
  expressResponse.statusCode = responseInfo.status;
39
39
  if (responseInfo.body && responseInfo.body.json) {
40
40
  expressResponse.send(responseInfo.body.json);
41
- } else
41
+ } else if (responseInfo.body && responseInfo.body.buffer)
42
+ expressResponse.send(responseInfo.body.buffer);
43
+ else
42
44
  expressResponse.send();
43
45
  return expressResponse;
44
46
  }
package/dist/index.mjs CHANGED
@@ -7,18 +7,18 @@ import { GET, FrameworkType, getPort } from '@nattyjs/common';
7
7
  async function getRequestBodyInfo(request) {
8
8
  const contentType = request.headers["content-type"];
9
9
  const bodyInfo = {};
10
- if (request.method !== GET)
11
- switch (contentType) {
12
- case "application/json":
13
- bodyInfo.json = request.body;
14
- break;
15
- }
10
+ if (request.method !== GET) {
11
+ if (contentType && contentType.toLowerCase().indexOf("application/json") > -1)
12
+ bodyInfo.json = request.body;
13
+ }
16
14
  return bodyInfo;
17
15
  }
18
16
 
19
17
  function getResponse(expressResponse, responseInfo) {
20
18
  if (responseInfo.headers)
21
- Object.keys(responseInfo.headers).forEach((key) => expressResponse.set(key, responseInfo.headers[key]));
19
+ for (const pair of responseInfo.headers.entries()) {
20
+ expressResponse.setHeader(pair[0], pair[1]);
21
+ }
22
22
  if (responseInfo.cookies)
23
23
  responseInfo.cookies.forEach((cookie) => {
24
24
  const name = cookie.name;
@@ -30,7 +30,9 @@ function getResponse(expressResponse, responseInfo) {
30
30
  expressResponse.statusCode = responseInfo.status;
31
31
  if (responseInfo.body && responseInfo.body.json) {
32
32
  expressResponse.send(responseInfo.body.json);
33
- } else
33
+ } else if (responseInfo.body && responseInfo.body.buffer)
34
+ expressResponse.send(responseInfo.body.buffer);
35
+ else
34
36
  expressResponse.send();
35
37
  return expressResponse;
36
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/express",
3
- "version": "0.0.1-beta.30",
3
+ "version": "0.0.1-beta.32",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha <ojhaajay@outlook.com>",
@@ -18,9 +18,9 @@
18
18
  "express": "4.18.2",
19
19
  "cors": "2.8.5",
20
20
  "compression": "1.7.4",
21
- "@nattyjs/core": "0.0.1-beta.30",
22
- "@nattyjs/common": "0.0.1-beta.30",
23
- "@nattyjs/types": "0.0.1-beta.30"
21
+ "@nattyjs/core": "0.0.1-beta.32",
22
+ "@nattyjs/common": "0.0.1-beta.32",
23
+ "@nattyjs/types": "0.0.1-beta.32"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "20.3.1",