systemlynx 1.8.3 → 1.9.4
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/package.json
CHANGED
package/systemlynx/App/App.js
CHANGED
|
@@ -11,11 +11,16 @@ module.exports = function createApp(server, WebSocket, customClient) {
|
|
|
11
11
|
const systemContext = SystemLynxContext(system);
|
|
12
12
|
const App = new createDispatcher(undefined, systemContext);
|
|
13
13
|
const plugins = [];
|
|
14
|
-
|
|
14
|
+
const init = () => {
|
|
15
15
|
plugins.forEach((plugin) => {
|
|
16
16
|
if (typeof plugin === "function") plugin.apply({}, [App, system]);
|
|
17
17
|
});
|
|
18
18
|
initializeApp(system, App, customClient, systemContext);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let timeoutId = setTimeout(() => {
|
|
22
|
+
timeoutId = null;
|
|
23
|
+
init();
|
|
19
24
|
}, 0);
|
|
20
25
|
|
|
21
26
|
if (isNode) {
|
|
@@ -23,6 +28,12 @@ module.exports = function createApp(server, WebSocket, customClient) {
|
|
|
23
28
|
|
|
24
29
|
App.startService = (options) => {
|
|
25
30
|
system.routing = options;
|
|
31
|
+
if (!timeoutId) {
|
|
32
|
+
timeoutId = setTimeout(() => {
|
|
33
|
+
timeoutId = null;
|
|
34
|
+
init();
|
|
35
|
+
}, 0);
|
|
36
|
+
}
|
|
26
37
|
return App;
|
|
27
38
|
};
|
|
28
39
|
|
|
@@ -5,17 +5,19 @@ module.exports = function loadConnectionData(
|
|
|
5
5
|
) {
|
|
6
6
|
const errors = [];
|
|
7
7
|
|
|
8
|
-
return new Promise(function getData(resolve) {
|
|
8
|
+
return new Promise(function getData(resolve, reject) {
|
|
9
9
|
httpClient.request({ method: "GET", url }, (err, results) => {
|
|
10
10
|
if (err) {
|
|
11
11
|
errors.push(err);
|
|
12
12
|
|
|
13
13
|
if (errors.length < limit)
|
|
14
|
-
setTimeout(() => getData(resolve), errors.length * wait);
|
|
15
|
-
else
|
|
14
|
+
setTimeout(() => getData(resolve, reject), errors.length * wait);
|
|
15
|
+
else {
|
|
16
16
|
console.error(
|
|
17
17
|
`[SystemLynx][Client][Error]: Failed to load Service @${url} after ${errors.length} attempts.`
|
|
18
18
|
);
|
|
19
|
+
reject(err);
|
|
20
|
+
}
|
|
19
21
|
} else resolve(results);
|
|
20
22
|
});
|
|
21
23
|
});
|
|
@@ -6,11 +6,22 @@ module.exports = function createClient() {
|
|
|
6
6
|
const Client = this || {};
|
|
7
7
|
Client.request = ({ method, url, body }, cb) => {
|
|
8
8
|
const tryRequest = (callback) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const req = httpClient(
|
|
10
|
+
{
|
|
11
|
+
method,
|
|
12
|
+
url,
|
|
13
|
+
body,
|
|
14
|
+
json,
|
|
15
|
+
headers: {
|
|
16
|
+
Origin: "http://localhost:3000", // Replace with your desired origin
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
(err, res, body) => {
|
|
20
|
+
if (err) callback(err);
|
|
21
|
+
else if (res.statusCode >= 400) callback(body);
|
|
22
|
+
else callback(null, body, res);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
14
25
|
};
|
|
15
26
|
if (typeof cb === "function") tryRequest(cb);
|
|
16
27
|
else
|
|
@@ -138,6 +138,14 @@ module.exports = function createServerManager(customServer, customWebSocketServe
|
|
|
138
138
|
ServerManager.addRouteHandler = (...args) => {
|
|
139
139
|
const name = typeof args[0] === "string" ? args.shift() : "$all";
|
|
140
140
|
args.forEach(async (middleware) => {
|
|
141
|
+
if (Array.isArray(middleware)) {
|
|
142
|
+
middleware.map(addMiddleware);
|
|
143
|
+
} else {
|
|
144
|
+
addMiddleware(middleware);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
function addMiddleware(middleware) {
|
|
141
149
|
if (!serverConfigurations.validators[name])
|
|
142
150
|
serverConfigurations.validators[name] = [];
|
|
143
151
|
serverConfigurations.validators[name].push(async function (req, res, next) {
|
|
@@ -147,7 +155,7 @@ module.exports = function createServerManager(customServer, customWebSocketServe
|
|
|
147
155
|
res.sendError(error);
|
|
148
156
|
}
|
|
149
157
|
});
|
|
150
|
-
}
|
|
158
|
+
}
|
|
151
159
|
};
|
|
152
160
|
return ServerManager;
|
|
153
161
|
};
|