ismx-nexo-node-app 0.4.171 → 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.
- package/dist/js/business/BusinessLogger.js +9 -7
- package/dist/js/business/BusinessServer.js +14 -11
- package/dist/types/business/BusinessLogger.d.ts +2 -0
- package/dist/types/business/BusinessServer.d.ts +2 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessLogger.ts +15 -9
- package/src/main/node/business/BusinessServer.ts +17 -11
|
@@ -23,12 +23,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs"));
|
|
27
|
-
const path = __importStar(require("path"));
|
|
28
26
|
class BusinessLogger {
|
|
29
27
|
constructor() {
|
|
30
28
|
this.logStream = null;
|
|
31
29
|
this.currentLogFile = null;
|
|
30
|
+
Promise.resolve().then(() => __importStar(require("fs"))).then((e) => this.fs = e.default)
|
|
31
|
+
.catch(() => null);
|
|
32
|
+
Promise.resolve().then(() => __importStar(require("path"))).then((e) => this.path = e.default)
|
|
33
|
+
.catch(() => null);
|
|
32
34
|
}
|
|
33
35
|
file() {
|
|
34
36
|
return null;
|
|
@@ -42,16 +44,16 @@ class BusinessLogger {
|
|
|
42
44
|
this.logStream.end();
|
|
43
45
|
this.logStream = null;
|
|
44
46
|
}
|
|
45
|
-
const dir = path.dirname(file);
|
|
46
|
-
if (!fs.existsSync(dir))
|
|
47
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
48
|
-
this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
47
|
+
const dir = this.path.dirname(file);
|
|
48
|
+
if (!this.fs.existsSync(dir))
|
|
49
|
+
this.fs.mkdirSync(dir, { recursive: true });
|
|
50
|
+
this.logStream = this.fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
49
51
|
this.currentLogFile = file;
|
|
50
52
|
}
|
|
51
53
|
if (this.logStream)
|
|
52
54
|
this.logStream.write(message + '\n');
|
|
53
55
|
}
|
|
54
|
-
log(level, message
|
|
56
|
+
log(level, message) {
|
|
55
57
|
const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
|
|
56
58
|
console.log(logMessage);
|
|
57
59
|
this.writeToFile(logMessage);
|
|
@@ -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,13 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as path from 'path';
|
|
1
|
+
import {WriteStream} from "node:fs";
|
|
3
2
|
|
|
4
3
|
export default class BusinessLogger
|
|
5
4
|
{
|
|
6
|
-
private logStream:
|
|
5
|
+
private logStream: WriteStream | null = null;
|
|
7
6
|
private currentLogFile: string | null = null;
|
|
7
|
+
private fs: any;
|
|
8
|
+
private path: any;
|
|
8
9
|
|
|
9
10
|
constructor() {
|
|
10
|
-
|
|
11
|
+
import("fs")
|
|
12
|
+
.then((e) => this.fs = e.default)
|
|
13
|
+
.catch(() => null);
|
|
14
|
+
import("path")
|
|
15
|
+
.then((e) => this.path = e.default)
|
|
16
|
+
.catch(() => null);
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
protected file(): string | null {
|
|
@@ -24,18 +30,18 @@ export default class BusinessLogger
|
|
|
24
30
|
this.logStream = null;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
const dir = path.dirname(file);
|
|
28
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
29
|
-
this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
33
|
+
const dir = this.path.dirname(file);
|
|
34
|
+
if (!this.fs.existsSync(dir)) this.fs.mkdirSync(dir, { recursive: true });
|
|
35
|
+
this.logStream = this.fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
|
|
30
36
|
this.currentLogFile = file;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
if (this.logStream) this.logStream.write(message + '\n');
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
private log(level: string, message: string
|
|
42
|
+
private log(level: string, message: string) {
|
|
37
43
|
const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
|
|
38
|
-
console.log(logMessage);this.writeToFile(logMessage);
|
|
44
|
+
console.log(logMessage); this.writeToFile(logMessage);
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
i(message: string) {
|
|
@@ -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) { }
|