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("dotenv").config()
|
||||||
require("sucrase/register")
|
require("sucrase/register")
|
||||||
|
|
||||||
const path = require("path")
|
const path = require("node:path")
|
||||||
const Module = require("module")
|
const Module = require("node:module")
|
||||||
const { Buffer } = require("buffer")
|
const { Buffer } = require("node:buffer")
|
||||||
const { webcrypto: crypto } = require("crypto")
|
const { webcrypto: crypto } = require("node:crypto")
|
||||||
const { InfisicalClient } = require("@infisical/sdk")
|
const { InfisicalClient } = require("@infisical/sdk")
|
||||||
|
|
||||||
const moduleAlias = require("module-alias")
|
const moduleAlias = require("module-alias")
|
||||||
|
const { onExit } = require("signal-exit")
|
||||||
|
|
||||||
// Override file execution arg
|
// Override file execution arg
|
||||||
process.argv.splice(1, 1)
|
process.argv.splice(1, 1)
|
||||||
@ -108,7 +108,12 @@ async function injectEnvFromInfisical() {
|
|||||||
console.log(`[BOOT] 🔑 Injecting env variables from INFISICAL in [${envMode}] mode...`)
|
console.log(`[BOOT] 🔑 Injecting env variables from INFISICAL in [${envMode}] mode...`)
|
||||||
|
|
||||||
const client = new InfisicalClient({
|
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({
|
const secrets = await client.listSecrets({
|
||||||
@ -127,18 +132,31 @@ async function injectEnvFromInfisical() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function Boot(main) {
|
async function Boot(main) {
|
||||||
try {
|
|
||||||
if (!main) {
|
if (!main) {
|
||||||
throw new Error("main class is not defined")
|
throw new Error("main class is not defined")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
console.log(`[BOOT] Booting in [${global.isProduction ? "production" : "development"}] mode...`)
|
||||||
console.log(`[BOOT] INFISICAL_TOKEN found, injecting env variables from INFISICAL...`)
|
|
||||||
|
if (process.env.INFISICAL_CLIENT_ID && process.env.INFISICAL_CLIENT_SECRET) {
|
||||||
|
console.log(`[BOOT] INFISICAL Credentials found, injecting env variables from INFISICAL...`)
|
||||||
await injectEnvFromInfisical()
|
await injectEnvFromInfisical()
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = new main()
|
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()
|
await instance.initialize()
|
||||||
|
|
||||||
if (process.env.lb_service && process.send) {
|
if (process.env.lb_service && process.send) {
|
||||||
@ -148,14 +166,9 @@ async function Boot(main) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[BOOT] Booting in [${global.isProduction ? "production" : "development"}] mode...`)
|
try {
|
||||||
|
|
||||||
// Apply patches
|
// Apply patches
|
||||||
registerPatches()
|
registerPatches()
|
||||||
|
|
||||||
@ -164,3 +177,6 @@ registerAliases()
|
|||||||
|
|
||||||
// execute main
|
// execute main
|
||||||
Module.runMain()
|
Module.runMain()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[BOOT] ❌ Boot error: ", error)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user