From fadbc41c0173b0ac9bb94de59c9ba2b30f0fd1ca Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 30 Sep 2024 02:33:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20build:=20fix=20zeabur=20build=20?= =?UTF-8?q?(#4213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 👷 build: add `SKIP_DB_MIGRATION` ENV * 🔨 chore: change logic * 💄 style: update error output style * Update startServer.js * 👷 build: detect DB_MIGRATION_SCRIPT_PATH, if not exist then skip * 🔨 chore: improve console log * 🔨 chore: add skip reason * 🐛 fix: fix fs calling error * 🐛 fix: fix `proxychains` conf generate error * 🔨 chore: fix catch error * 🐛 fix: fix typo --- scripts/serverLauncher/startServer.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/serverLauncher/startServer.js b/scripts/serverLauncher/startServer.js index d980702ee7..97d1e8587e 100644 --- a/scripts/serverLauncher/startServer.js +++ b/scripts/serverLauncher/startServer.js @@ -1,5 +1,5 @@ const dns = require('dns').promises; -const fs = require('fs'); +const fs = require('fs').promises; const tls = require('tls'); const { spawn } = require('child_process'); @@ -102,7 +102,8 @@ const resolveHostIP = async (host, version = 4) => { return address; } catch (err) { - console.error(`❌ DNS Error: Could not resolve ${host}. Check DNS server.`, err); + console.error(`❌ DNS Error: Could not resolve ${host}. Check DNS server:`); + console.error(err); process.exit(1); } }; @@ -136,7 +137,7 @@ tcp_read_time_out 15000 ${protocol} ${ip} ${port} `.trim(); - fs.writeFileSync(PROXYCHAINS_CONF_PATH, configContent); + await fs.writeFile(PROXYCHAINS_CONF_PATH, configContent); console.log(`✅ ProxyChains: All outgoing traffic routed via ${protocol}://${ip}:${port}.`); console.log('-------------------------------------'); }; @@ -168,10 +169,25 @@ const runServer = async () => { if (process.env.DATABASE_DRIVER) { try { - await runScript(DB_MIGRATION_SCRIPT_PATH); + try { + await fs.access(DB_MIGRATION_SCRIPT_PATH); + + await runScript(DB_MIGRATION_SCRIPT_PATH); + } catch (err) { + if (err.code === 'ENOENT') { + console.log(`⚠️ DB Migration: Not found ${DB_MIGRATION_SCRIPT_PATH}. Skipping DB migration. Ensure to migrate database manually.`); + console.log('-------------------------------------'); + } else { + console.error('❌ Error during DB migration:'); + console.error(err); + process.exit(1); + } + } + await checkTLSConnections(); } catch (err) { - console.error('❌ Error during DB migration or TLS connection check:', err); + console.error('❌ Error during TLS connection check:'); + console.error(err); process.exit(1); } }