ismx-nexo-node-app 0.4.190 → 0.4.192
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/js/business/BusinessServer.js +5 -1
- package/dist/js/repository/RepositoryRest.js +3 -1
- package/dist/types/api/Service.d.ts +2 -1
- package/package.json +1 -1
- package/src/main/node/api/Service.ts +3 -1
- package/src/main/node/business/BusinessServer.ts +4 -1
- package/src/main/node/repository/RepositoryRest.ts +3 -1
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const Service_1 = require("../api/Service");
|
|
39
39
|
const Business_1 = __importDefault(require("./Business"));
|
|
40
|
+
const node_http_1 = require("node:http");
|
|
40
41
|
class BusinessServer extends Business_1.default {
|
|
41
42
|
constructor() {
|
|
42
43
|
super();
|
|
@@ -162,7 +163,10 @@ class BusinessServer extends Business_1.default {
|
|
|
162
163
|
socket.set(header, value);
|
|
163
164
|
});
|
|
164
165
|
if (response.pipe)
|
|
165
|
-
|
|
166
|
+
if (response.pipe instanceof node_http_1.IncomingMessage)
|
|
167
|
+
response.pipe.pipe(socket);
|
|
168
|
+
else
|
|
169
|
+
this.readable.fromWeb(response.pipe).pipe(socket);
|
|
166
170
|
else
|
|
167
171
|
socket.send(response === null || response === void 0 ? void 0 : response.content);
|
|
168
172
|
try {
|
|
@@ -38,7 +38,9 @@ class RepositoryRest extends Repository_1.default {
|
|
|
38
38
|
headers.set('Pragma', 'no-cache');
|
|
39
39
|
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
40
40
|
let body = request.body;
|
|
41
|
-
|
|
41
|
+
let isBuffer = typeof Buffer !== 'undefined' && Buffer.isBuffer(request.body);
|
|
42
|
+
let isForm = typeof FormData !== 'undefined' && (request.body instanceof FormData);
|
|
43
|
+
if (!((_d = request.headers) === null || _d === void 0 ? void 0 : _d["Content-Type"]) && request.body && typeof request.body !== 'string' && !isBuffer && !isForm) {
|
|
42
44
|
headers.set('Content-Type', 'application/json');
|
|
43
45
|
body = JSON.stringify(request.body);
|
|
44
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncomingMessage } from "node:http";
|
|
1
2
|
export interface HttpRequest<T = any> {
|
|
2
3
|
id?: string;
|
|
3
4
|
url?: string;
|
|
@@ -30,7 +31,7 @@ export declare class HttpResponse<T = any> {
|
|
|
30
31
|
headers?: {
|
|
31
32
|
[key: string]: string;
|
|
32
33
|
};
|
|
33
|
-
pipe?: ReadableStream;
|
|
34
|
+
pipe?: ReadableStream | IncomingMessage;
|
|
34
35
|
static ok<T = any>(content: T): HttpResponse<any>;
|
|
35
36
|
static ko<T = any>(httpCode: number, content: T): HttpResponse<any>;
|
|
36
37
|
static do<T = any>(httpCode: number, content: T): HttpResponse<any>;
|
package/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {IncomingMessage} from "node:http";
|
|
2
|
+
|
|
1
3
|
export interface HttpRequest<T = any> {
|
|
2
4
|
id?: string,
|
|
3
5
|
url?: string,
|
|
@@ -24,7 +26,7 @@ export class HttpResponse<T = any> {
|
|
|
24
26
|
content: T = null!;
|
|
25
27
|
httpCode?: number;
|
|
26
28
|
headers?: { [key: string]: string };
|
|
27
|
-
pipe?: ReadableStream;
|
|
29
|
+
pipe?: ReadableStream | IncomingMessage;
|
|
28
30
|
|
|
29
31
|
static ok<T=any>(content: T) {
|
|
30
32
|
let response = new HttpResponse();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Service, {HttpRequest, HttpResponse} from "../api/Service";
|
|
2
2
|
import Business from "./Business";
|
|
3
|
+
import {IncomingMessage} from "node:http";
|
|
3
4
|
|
|
4
5
|
export default class BusinessServer extends Business
|
|
5
6
|
{
|
|
@@ -130,7 +131,9 @@ export default class BusinessServer extends Business
|
|
|
130
131
|
Object.entries(response.headers ?? {}).forEach(([header, value]) => {
|
|
131
132
|
socket.set(header, value);
|
|
132
133
|
});
|
|
133
|
-
if (response.pipe)
|
|
134
|
+
if (response.pipe)
|
|
135
|
+
if (response.pipe instanceof IncomingMessage) response.pipe.pipe(socket);
|
|
136
|
+
else this.readable.fromWeb(response.pipe).pipe(socket);
|
|
134
137
|
else socket.send(response?.content);
|
|
135
138
|
|
|
136
139
|
try { this.onEnd?.(request, response); } catch(e) { }
|
|
@@ -48,7 +48,9 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
48
48
|
|
|
49
49
|
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
50
50
|
let body: string | undefined = request.body as string;
|
|
51
|
-
|
|
51
|
+
let isBuffer = typeof Buffer !== 'undefined' && Buffer.isBuffer(request.body);
|
|
52
|
+
let isForm = typeof FormData !== 'undefined' && (request.body instanceof FormData);
|
|
53
|
+
if (!request.headers?.["Content-Type"] && request.body && typeof request.body !== 'string' && !isBuffer && !isForm) {
|
|
52
54
|
headers.set('Content-Type', 'application/json');
|
|
53
55
|
body = JSON.stringify(request.body);
|
|
54
56
|
}
|