ismx-nexo-node-app 0.4.172 → 0.4.173
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.
|
@@ -37,30 +37,33 @@ 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_stream_1 = require("node:stream");
|
|
41
40
|
class BusinessServer extends Business_1.default {
|
|
42
41
|
constructor() {
|
|
43
42
|
super();
|
|
44
43
|
this.services = [];
|
|
45
44
|
this.publish = this.publish.bind(this);
|
|
45
|
+
Promise.resolve().then(() => __importStar(require("express"))).then((e) => this.express = e.default);
|
|
46
|
+
Promise.resolve().then(() => __importStar(require("cors"))).then((e) => this.cors = e.default);
|
|
47
|
+
Promise.resolve().then(() => __importStar(require("node:stream"))).then((e) => this.readable = e.default.Readable);
|
|
46
48
|
}
|
|
47
49
|
init() {
|
|
48
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
this.app = this.express();
|
|
52
|
+
this.app.use(this.express.urlencoded({ extended: false }));
|
|
53
|
+
this.app.use(this.cors({
|
|
54
|
+
origin: true,
|
|
55
|
+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
56
|
+
allowedHeaders: ["Authorization", "Content-Type"],
|
|
57
|
+
exposedHeaders: ["Authorization"],
|
|
58
|
+
credentials: false
|
|
59
|
+
}));
|
|
60
|
+
this.app.options("*", this.cors({
|
|
57
61
|
origin: true,
|
|
58
62
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
59
63
|
allowedHeaders: ["Authorization", "Content-Type"],
|
|
60
64
|
exposedHeaders: ["Authorization"],
|
|
61
65
|
credentials: false
|
|
62
66
|
}));
|
|
63
|
-
this.app.options("*", cors());
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
start(port) {
|
|
@@ -156,7 +159,7 @@ class BusinessServer extends Business_1.default {
|
|
|
156
159
|
socket.set(header, value);
|
|
157
160
|
});
|
|
158
161
|
if (response.pipe)
|
|
159
|
-
|
|
162
|
+
this.readable.fromWeb(response.pipe).pipe(socket);
|
|
160
163
|
else
|
|
161
164
|
socket.send(response === null || response === void 0 ? void 0 : response.content);
|
|
162
165
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Service, {HttpRequest, HttpResponse} from "../api/Service";
|
|
2
2
|
import Business from "./Business";
|
|
3
|
-
import {Readable} from "node:stream";
|
|
4
3
|
|
|
5
4
|
export default class BusinessServer extends Business
|
|
6
5
|
{
|
|
@@ -9,23 +8,24 @@ export default class BusinessServer extends Business
|
|
|
9
8
|
private express: any;
|
|
10
9
|
|
|
11
10
|
private app: any;
|
|
11
|
+
private cors: any;
|
|
12
|
+
private readable: any;
|
|
12
13
|
|
|
13
14
|
constructor() {
|
|
14
15
|
super()
|
|
15
16
|
this.publish = this.publish.bind(this);
|
|
17
|
+
|
|
18
|
+
import("express").then((e) => this.express = e.default);
|
|
19
|
+
import("cors").then((e) => this.cors = e.default)
|
|
20
|
+
import("node:stream").then((e) => this.readable = e.default.Readable)
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
async init()
|
|
19
24
|
{
|
|
20
|
-
|
|
21
|
-
const cors = await import("cors").then((e) => e.default).catch(() => null);
|
|
22
|
-
if (!express || !cors) return;
|
|
23
|
-
|
|
24
|
-
this.express = express;
|
|
25
|
-
this.app = express();
|
|
25
|
+
this.app = this.express();
|
|
26
26
|
|
|
27
|
-
this.app.use(express.urlencoded({ extended: false }));
|
|
28
|
-
this.app.use(cors({
|
|
27
|
+
this.app.use(this.express.urlencoded({ extended: false }));
|
|
28
|
+
this.app.use(this.cors({
|
|
29
29
|
origin: true,
|
|
30
30
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
31
31
|
allowedHeaders: ["Authorization", "Content-Type"],
|
|
@@ -33,7 +33,13 @@ export default class BusinessServer extends Business
|
|
|
33
33
|
credentials: false
|
|
34
34
|
}));
|
|
35
35
|
|
|
36
|
-
this.app.options("*", cors(
|
|
36
|
+
this.app.options("*", this.cors({
|
|
37
|
+
origin: true,
|
|
38
|
+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
39
|
+
allowedHeaders: ["Authorization", "Content-Type"],
|
|
40
|
+
exposedHeaders: ["Authorization"],
|
|
41
|
+
credentials: false
|
|
42
|
+
}));
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
start(port: number) {
|
|
@@ -120,7 +126,7 @@ export default class BusinessServer extends Business
|
|
|
120
126
|
Object.entries(response.headers ?? {}).forEach(([header, value]) => {
|
|
121
127
|
socket.set(header, value);
|
|
122
128
|
});
|
|
123
|
-
if (response.pipe)
|
|
129
|
+
if (response.pipe) this.readable.fromWeb(response.pipe).pipe(socket);
|
|
124
130
|
else socket.send(response?.content);
|
|
125
131
|
|
|
126
132
|
try { this.onEnd?.(request, response); } catch(e) { }
|