Skip to content

Commit b71f59c

Browse files
committed
Backup .env/port.txt in deploy workflow, graceful fallback in server.js
1 parent 53208f8 commit b71f59c

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/deploy-beta.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
port: ${{ secrets.SSH_PORT || 22 }}
1818
script: |
1919
cd ${{ secrets.BETA_PATH }}
20+
cp .env /tmp/beta.env 2>/dev/null; cp port.txt /tmp/beta.port.txt 2>/dev/null
2021
git fetch origin
2122
git checkout -f -B beta origin/beta
23+
cp /tmp/beta.env .env 2>/dev/null; cp /tmp/beta.port.txt port.txt 2>/dev/null
2224
npm install
2325
pm2 restart beta

.github/workflows/deploy-main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
port: ${{ secrets.SSH_PORT || 22 }}
1818
script: |
1919
cd ${{ secrets.MAIN_PATH }}
20+
cp .env /tmp/main.env 2>/dev/null; cp port.txt /tmp/main.port.txt 2>/dev/null
2021
git fetch origin
2122
git checkout -f -B main origin/main
23+
cp /tmp/main.env .env 2>/dev/null; cp /tmp/main.port.txt port.txt 2>/dev/null
2224
npm install
2325
pm2 restart zerohost-dashboard

server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import { migrate } from './config/migrate.js';
2020
import { query } from './config/db.js';
2121

2222
const app = express();
23-
const PORT = process.env.PORT || parseInt(readFileSync(resolve(__dirname, 'port.txt'), 'utf-8').trim(), 10) || 3000;
23+
let portFromFile = 3000;
24+
try { portFromFile = parseInt(readFileSync(resolve(__dirname, 'port.txt'), 'utf-8').trim(), 10) || 3000; } catch {}
25+
const PORT = process.env.PORT || portFromFile;
2426

2527
const trustProxy = process.env.NODE_ENV === 'production';
2628

0 commit comments

Comments
 (0)