mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
improve bootloader
This commit is contained in:
parent
d2e6f1bc58
commit
a462d5bb9b
46
bin/boot.js
46
bin/boot.js
@ -2,13 +2,13 @@
|
||||
require("dotenv").config()
|
||||
require("sucrase/register")
|
||||
|
||||
const path = require("path")
|
||||
const Module = require("module")
|
||||
const { Buffer } = require("buffer")
|
||||
const { webcrypto: crypto } = require("crypto")
|
||||
const path = require("node:path")
|
||||
const Module = require("node:module")
|
||||
const { Buffer } = require("node:buffer")
|
||||
const { webcrypto: crypto } = require("node:crypto")
|
||||
const { InfisicalClient } = require("@infisical/sdk")
|
||||
|
||||
const moduleAlias = require("module-alias")
|
||||
const { onExit } = require("signal-exit")
|
||||
|
||||
// Override file execution arg
|
||||
process.argv.splice(1, 1)
|
||||
@ -108,7 +108,12 @@ async function injectEnvFromInfisical() {
|
||||
console.log(`[BOOT] 🔑 Injecting env variables from INFISICAL in [${envMode}] mode...`)
|
||||
|
||||
const client = new InfisicalClient({
|
||||
accessToken: process.env.INFISICAL_TOKEN,
|
||||
auth: {
|
||||
universalAuth: {
|
||||
clientId: process.env.INFISICAL_CLIENT_ID,
|
||||
clientSecret: process.env.INFISICAL_CLIENT_SECRET,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const secrets = await client.listSecrets({
|
||||
@ -127,18 +132,31 @@ async function injectEnvFromInfisical() {
|
||||
}
|
||||
|
||||
async function Boot(main) {
|
||||
try {
|
||||
if (!main) {
|
||||
throw new Error("main class is not defined")
|
||||
}
|
||||
|
||||
if (process.env.INFISICAL_TOKEN) {
|
||||
console.log(`[BOOT] INFISICAL_TOKEN found, injecting env variables from INFISICAL...`)
|
||||
console.log(`[BOOT] Booting in [${global.isProduction ? "production" : "development"}] mode...`)
|
||||
|
||||
if (process.env.INFISICAL_CLIENT_ID && process.env.INFISICAL_CLIENT_SECRET) {
|
||||
console.log(`[BOOT] INFISICAL Credentials found, injecting env variables from INFISICAL...`)
|
||||
await injectEnvFromInfisical()
|
||||
}
|
||||
|
||||
const instance = new main()
|
||||
|
||||
onExit((code, signal) => {
|
||||
console.log(`[BOOT] Cleaning up...`)
|
||||
|
||||
if (typeof instance.onClose === "function") {
|
||||
instance.onClose()
|
||||
}
|
||||
|
||||
instance.engine.close()
|
||||
}, {
|
||||
alwaysLast: true,
|
||||
})
|
||||
|
||||
await instance.initialize()
|
||||
|
||||
if (process.env.lb_service && process.send) {
|
||||
@ -148,14 +166,9 @@ async function Boot(main) {
|
||||
}
|
||||
|
||||
return instance
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[BOOT] Booting in [${global.isProduction ? "production" : "development"}] mode...`)
|
||||
|
||||
try {
|
||||
// Apply patches
|
||||
registerPatches()
|
||||
|
||||
@ -164,3 +177,6 @@ registerAliases()
|
||||
|
||||
// execute main
|
||||
Module.runMain()
|
||||
} catch (error) {
|
||||
console.error("[BOOT] ❌ Boot error: ", error)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user