@cadenza.io/service 1.17.1 → 1.17.3
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/index.js +69 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -730,7 +730,14 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
730
730
|
).emits("meta.service_registry.service_inserted").emitsOnFail("meta.service_registry.service_insertion_failed");
|
|
731
731
|
this.insertServiceInstanceTask = CadenzaService.createCadenzaDBInsertTask(
|
|
732
732
|
"serviceInstance",
|
|
733
|
-
{
|
|
733
|
+
{
|
|
734
|
+
onConflict: {
|
|
735
|
+
target: ["address", "port", "process_pid"],
|
|
736
|
+
action: {
|
|
737
|
+
do: "nothing"
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
},
|
|
734
741
|
{
|
|
735
742
|
inputSchema: {
|
|
736
743
|
type: "object",
|
|
@@ -1141,34 +1148,37 @@ var RestController = class _RestController {
|
|
|
1141
1148
|
).then(
|
|
1142
1149
|
CadenzaService.createMetaTask(
|
|
1143
1150
|
"Configure network",
|
|
1144
|
-
(ctx) => {
|
|
1151
|
+
async (ctx) => {
|
|
1145
1152
|
let address = "localhost";
|
|
1146
1153
|
let port = ctx.__port;
|
|
1147
1154
|
let exposed = false;
|
|
1148
|
-
const createHttpServer = (ctx2) => {
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
if (
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1155
|
+
const createHttpServer = async (ctx2) => {
|
|
1156
|
+
await new Promise((resolve, reject) => {
|
|
1157
|
+
const server = import_node_http.default.createServer(ctx2.__app);
|
|
1158
|
+
ctx2.__httpServer = server;
|
|
1159
|
+
server.listen(ctx2.__port, () => {
|
|
1160
|
+
if (typeof server?.address() === "string") {
|
|
1161
|
+
address = server.address();
|
|
1162
|
+
} else if (server?.address()?.address === "::") {
|
|
1163
|
+
if (process.env.NODE_ENV === "development") {
|
|
1164
|
+
address = "localhost";
|
|
1165
|
+
} else if (process.env.IS_DOCKER === "true") {
|
|
1166
|
+
address = process.env.CADENZA_SERVER_URL || "localhost";
|
|
1167
|
+
}
|
|
1168
|
+
} else {
|
|
1169
|
+
address = server?.address()?.address || "";
|
|
1159
1170
|
}
|
|
1160
|
-
|
|
1161
|
-
address
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1171
|
+
console.log(`Server is running on ${address}:${port}`);
|
|
1172
|
+
resolve(address);
|
|
1173
|
+
});
|
|
1174
|
+
CadenzaService.createMetaTask(
|
|
1175
|
+
"Shutdown HTTP Server",
|
|
1176
|
+
() => server.close(),
|
|
1177
|
+
"Shuts down the HTTP server"
|
|
1178
|
+
).doOn("meta.server_shutdown_requested").emits("meta.rest.shutdown:http");
|
|
1164
1179
|
});
|
|
1165
|
-
CadenzaService.createMetaTask(
|
|
1166
|
-
"Shutdown HTTP Server",
|
|
1167
|
-
() => server.close(),
|
|
1168
|
-
"Shuts down the HTTP server"
|
|
1169
|
-
).doOn("meta.server_shutdown_requested").emits("meta.rest.shutdown:http");
|
|
1170
1180
|
};
|
|
1171
|
-
const createHttpsServer = (ctx2) => {
|
|
1181
|
+
const createHttpsServer = async (ctx2) => {
|
|
1172
1182
|
if (!process.env.SSL_KEY_PATH || !process.env.SSL_CERT_PATH) {
|
|
1173
1183
|
throw new Error(
|
|
1174
1184
|
"SSL_KEY_PATH and SSL_CERT_PATH must be set"
|
|
@@ -1178,38 +1188,46 @@ var RestController = class _RestController {
|
|
|
1178
1188
|
key: import_node_fs.default.readFileSync(process.env.SSL_KEY_PATH),
|
|
1179
1189
|
cert: import_node_fs.default.readFileSync(process.env.SSL_CERT_PATH)
|
|
1180
1190
|
};
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
+
await new Promise((resolve, reject) => {
|
|
1192
|
+
const httpsServer = import_node_https.default.createServer(
|
|
1193
|
+
options,
|
|
1194
|
+
ctx2.__app
|
|
1195
|
+
);
|
|
1196
|
+
ctx2.__httpsServer = httpsServer;
|
|
1197
|
+
ctx2.__port = 443;
|
|
1198
|
+
port = 443;
|
|
1199
|
+
httpsServer.listen(443, () => {
|
|
1200
|
+
if (typeof httpsServer?.address() === "string") {
|
|
1201
|
+
address = httpsServer.address();
|
|
1202
|
+
} else if (httpsServer?.address()?.address === "::") {
|
|
1203
|
+
if (process.env.IS_DOCKER === "true") {
|
|
1204
|
+
address = process.env.CADENZA_SERVER_URL || "localhost";
|
|
1205
|
+
}
|
|
1206
|
+
} else {
|
|
1207
|
+
address = httpsServer?.address()?.address || "";
|
|
1191
1208
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1209
|
+
exposed = true;
|
|
1210
|
+
console.log(
|
|
1211
|
+
`HTTPS Server is running on ${address}:443`
|
|
1212
|
+
);
|
|
1213
|
+
resolve(address);
|
|
1214
|
+
});
|
|
1215
|
+
CadenzaService.createMetaTask(
|
|
1216
|
+
"Shutdown HTTPS Server",
|
|
1217
|
+
() => httpsServer.close(),
|
|
1218
|
+
"Shuts down the HTTPS server"
|
|
1219
|
+
).doOn("meta.server_shutdown_requested").emits("meta.rest.shutdown:https");
|
|
1197
1220
|
});
|
|
1198
|
-
CadenzaService.createMetaTask(
|
|
1199
|
-
"Shutdown HTTPS Server",
|
|
1200
|
-
() => httpsServer.close(),
|
|
1201
|
-
"Shuts down the HTTPS server"
|
|
1202
|
-
).doOn("meta.server_shutdown_requested").emits("meta.rest.shutdown:https");
|
|
1203
1221
|
};
|
|
1204
1222
|
if (ctx.__networkMode === "internal" || ctx.__networkMode === "dev") {
|
|
1205
|
-
createHttpServer(ctx);
|
|
1223
|
+
await createHttpServer(ctx);
|
|
1206
1224
|
} else if (ctx.__networkMode === "exposed") {
|
|
1207
|
-
createHttpServer(ctx);
|
|
1208
|
-
createHttpsServer(ctx);
|
|
1225
|
+
await createHttpServer(ctx);
|
|
1226
|
+
await createHttpsServer(ctx);
|
|
1209
1227
|
} else if (ctx.__networkMode === "exposed-high-sec") {
|
|
1210
|
-
createHttpsServer(ctx);
|
|
1228
|
+
await createHttpsServer(ctx);
|
|
1211
1229
|
} else if (ctx.__networkMode === "auto") {
|
|
1212
|
-
createHttpServer(ctx);
|
|
1230
|
+
await createHttpServer(ctx);
|
|
1213
1231
|
}
|
|
1214
1232
|
ctx.data = {
|
|
1215
1233
|
uuid: ctx.__serviceInstanceId,
|
|
@@ -2331,9 +2349,10 @@ var DatabaseController = class _DatabaseController {
|
|
|
2331
2349
|
return def;
|
|
2332
2350
|
}).join(", ");
|
|
2333
2351
|
if (schema.meta?.dropExisting) {
|
|
2334
|
-
await this.dbClient.query(
|
|
2335
|
-
`
|
|
2352
|
+
const result = await this.dbClient.query(
|
|
2353
|
+
`DELETE FROM ${tableName};`
|
|
2336
2354
|
);
|
|
2355
|
+
console.log("DROP TABLE", tableName, result);
|
|
2337
2356
|
}
|
|
2338
2357
|
const sql = `CREATE TABLE IF NOT EXISTS ${tableName} (${fieldDefs})`;
|
|
2339
2358
|
ddl.push(sql);
|