Skip to content

Commit

Permalink
👷 build: fix zeabur build (lobehub#4213)
Browse files Browse the repository at this point in the history
* 👷 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
  • Loading branch information
hezhijie0327 authored Sep 29, 2024
1 parent 376261d commit fadbc41
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions scripts/serverLauncher/startServer.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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('-------------------------------------');
};
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit fadbc41

Please sign in to comment.