From 0c2964183a3ec9130c0413074e71af903eb4dd7b Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 13 Jul 2023 18:19:42 +0000 Subject: [PATCH] support `process.env.USE_LINKED_SHARED` --- packages/chat_server/src/index.js | 12 ++++++++++-- packages/file_server/src/index.js | 12 ++++++++++-- packages/marketplace_server/src/index.js | 12 ++++++++++-- packages/music_server/src/index.js | 18 +++++++----------- packages/server/src/index.js | 12 ++++++++++-- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/packages/chat_server/src/index.js b/packages/chat_server/src/index.js index 57895a24..b6edc90d 100755 --- a/packages/chat_server/src/index.js +++ b/packages/chat_server/src/index.js @@ -1,4 +1,3 @@ - import { webcrypto as crypto } from "crypto" import path from "path" import { registerBaseAliases } from "linebridge/dist/server" @@ -18,6 +17,11 @@ const customAliases = { if (!global.isProduction) { customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src") + + customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") +} + +if (process.env.USE_LINKED_SHARED) { customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") } @@ -69,7 +73,9 @@ async function main() { // inject to process.env secrets.forEach((secret) => { - process.env[secret.secretName] = secret.secretValue + if (!(secret.secretName in process.env)) { + process.env[secret.secretName] = secret.secretValue + } }) } @@ -82,6 +88,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) @@ -90,6 +97,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) diff --git a/packages/file_server/src/index.js b/packages/file_server/src/index.js index 57895a24..b6edc90d 100644 --- a/packages/file_server/src/index.js +++ b/packages/file_server/src/index.js @@ -1,4 +1,3 @@ - import { webcrypto as crypto } from "crypto" import path from "path" import { registerBaseAliases } from "linebridge/dist/server" @@ -18,6 +17,11 @@ const customAliases = { if (!global.isProduction) { customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src") + + customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") +} + +if (process.env.USE_LINKED_SHARED) { customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") } @@ -69,7 +73,9 @@ async function main() { // inject to process.env secrets.forEach((secret) => { - process.env[secret.secretName] = secret.secretValue + if (!(secret.secretName in process.env)) { + process.env[secret.secretName] = secret.secretValue + } }) } @@ -82,6 +88,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) @@ -90,6 +97,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) diff --git a/packages/marketplace_server/src/index.js b/packages/marketplace_server/src/index.js index 57895a24..b6edc90d 100644 --- a/packages/marketplace_server/src/index.js +++ b/packages/marketplace_server/src/index.js @@ -1,4 +1,3 @@ - import { webcrypto as crypto } from "crypto" import path from "path" import { registerBaseAliases } from "linebridge/dist/server" @@ -18,6 +17,11 @@ const customAliases = { if (!global.isProduction) { customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src") + + customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") +} + +if (process.env.USE_LINKED_SHARED) { customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") } @@ -69,7 +73,9 @@ async function main() { // inject to process.env secrets.forEach((secret) => { - process.env[secret.secretName] = secret.secretValue + if (!(secret.secretName in process.env)) { + process.env[secret.secretName] = secret.secretValue + } }) } @@ -82,6 +88,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) @@ -90,6 +97,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) diff --git a/packages/music_server/src/index.js b/packages/music_server/src/index.js index cb83e8f8..b6edc90d 100755 --- a/packages/music_server/src/index.js +++ b/packages/music_server/src/index.js @@ -17,6 +17,11 @@ const customAliases = { if (!global.isProduction) { customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src") + + customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") +} + +if (process.env.USE_LINKED_SHARED) { customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") } @@ -60,16 +65,12 @@ import API from "./api" async function main() { if (process.env.INFISICAL_TOKEN) { - console.log("🔑 Fetching secrets from Infisical...") - const client = new infisical({ token: process.env.INFISICAL_TOKEN, }) const secrets = await client.getAllSecrets() - console.log("🔑 Injecting secrets to process.env...",) - // inject to process.env secrets.forEach((secret) => { if (!(secret.secretName in process.env)) { @@ -78,13 +79,6 @@ async function main() { }) } - // transform "undefined" or "null" envs to undefined - Object.keys(process.env).forEach((key) => { - if (process.env[key] === "undefined" || process.env[key] === "null") { - process.env[key] = undefined - } - }) - const instance = new API() await instance.initialize() @@ -94,6 +88,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) @@ -102,6 +97,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) diff --git a/packages/server/src/index.js b/packages/server/src/index.js index 57895a24..b6edc90d 100755 --- a/packages/server/src/index.js +++ b/packages/server/src/index.js @@ -1,4 +1,3 @@ - import { webcrypto as crypto } from "crypto" import path from "path" import { registerBaseAliases } from "linebridge/dist/server" @@ -18,6 +17,11 @@ const customAliases = { if (!global.isProduction) { customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src") + + customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") +} + +if (process.env.USE_LINKED_SHARED) { customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes") } @@ -69,7 +73,9 @@ async function main() { // inject to process.env secrets.forEach((secret) => { - process.env[secret.secretName] = secret.secretValue + if (!(secret.secretName in process.env)) { + process.env[secret.secretName] = secret.secretValue + } }) } @@ -82,6 +88,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) }) @@ -90,6 +97,7 @@ async function main() { if (typeof instance.server.close === "function") { instance.server.close() } + process.exit(0) })