Selaa lähdekoodia

build, version bump

Pablo Barrera Yaksic 1 vuosi sitten
vanhempi
commit
5766a943b5
2 muutettua tiedostoa jossa 17 lisäystä ja 19 poistoa
  1. 16 18
      lib/index.js
  2. 1 1
      package.json

+ 16 - 18
lib/index.js

@@ -50,24 +50,22 @@ class PRAS {
                     res.json(this.getPRASResultObject(statusCode, status, message, data, code, extra));
                 },
             };
-            if (/application\/json/.test(res.get("Content-Type"))) {
-                const originalSend = res.send;
-                res.send = (body) => {
-                    if (typeof body === "string") {
-                        body = JSON.parse(body);
-                    }
-                    if (typeof body === "string") {
-                        body = { data: body };
-                    }
-                    else if (!body.hasOwnProperty("data")) {
-                        body = { data: body };
-                    }
-                    const prasBody = this.getPRASResultObject(body.statusCode, body.status, body.message, body.data, body.code, body.extra);
-                    res.status(Number(prasBody) || null);
-                    delete prasBody.statusCode;
-                    return originalSend(JSON.stringify(prasBody));
-                };
-            }
+            const originalSend = res.send;
+            res.send = (body) => {
+                if (typeof body === "string") {
+                    body = JSON.parse(body);
+                }
+                if (typeof body === "string") {
+                    body = { data: body };
+                }
+                else if (!body.hasOwnProperty("data")) {
+                    body = { data: body };
+                }
+                const prasBody = this.getPRASResultObject(body.statusCode, body.status, body.message, body.data, body.code, body.extra);
+                res.status(Number(prasBody.statusCode) || 200);
+                delete prasBody.statusCode;
+                return originalSend.call(res, JSON.stringify(prasBody));
+            };
             next();
         };
     }

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pablo/pablo-rest-api-standard",
-  "version": "0.0.6",
+  "version": "0.0.7",
   "description": "Pablo Rest API Standard Library",
   "main": "lib/index.js",
   "scripts": {