Skip to content

Commit ca9d95e

Browse files
committed
feat: run with no proxies.
1 parent c5a3c2c commit ca9d95e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
1010
## 使用 Docker 启动
1111

12+
### 准备代理 IP(可选)
13+
1214
将代理地址保存到 `proxies.txt` 文件中,格式为:
1315

1416
> socks5://username:password@proxyhost:port
@@ -23,7 +25,7 @@ docker run -d \
2325
overtrue/gradient-bot
2426
```
2527

26-
注意:`proxies.txt` 路径请替换为正确的路径,或者先 `cd``proxies.txt` 所在目录再执行 docker run 命令。
28+
注意:`proxies.txt` 路径请替换为正确的路径,如果没有代理,可以留空,或者先 `cd``proxies.txt` 所在目录再执行 docker run 命令。
2729

2830
## 查看运行日志
2931

start.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// 1. read proxies from file
22
const fs = require('fs')
33
const path = require('path')
4-
const proxies = fs.readFileSync(path.resolve(__dirname, 'proxies.txt'), 'utf-8').split('\n').filter(Boolean)
4+
5+
let proxies = []
6+
7+
try {
8+
proxies = fs.readFileSync(path.resolve(__dirname, 'proxies.txt'), 'utf-8').split('\n').filter(Boolean)
9+
} catch (error) {
10+
console.log('-> No proxies.txt found, or error reading file, will start app without proxy...')
11+
}
512

613
// 2. start pm2 with PROXY env
714
const { execSync } = require('child_process')
@@ -13,15 +20,22 @@ if (!USER || !PASSWORD) {
1320
process.exit()
1421
}
1522

16-
let index = 0
17-
for (const proxy of proxies) {
18-
const name = `gradient-${index++}`
19-
execSync(`PROXY=${proxy} APP_USER='${USER}' APP_PASS='${PASSWORD}' pm2 start app.js --name ${name}`)
20-
console.log(`-> Started ${name} with proxy ${proxy}`)
21-
}
23+
if (proxies.length === 0) {
24+
console.error("No proxies found in proxies.txt, will start app without proxy...")
25+
execSync(`APP_USER='${USER}' APP_PASS='${PASSWORD}' pm2 start app.js --name gradient-bot-no-proxy`)
26+
console.log('-> √ Started gradient-bot-no-proxy')
27+
} else {
28+
console.log(`-> Found ${proxies.length} proxies in proxies.txt`)
29+
let index = 0
30+
for (const proxy of proxies) {
31+
const name = `gradient-${index++}`
32+
execSync(`PROXY=${proxy} APP_USER='${USER}' APP_PASS='${PASSWORD}' pm2 start app.js --name ${name}`)
33+
console.log(`-> Started ${name} with proxy ${proxy}`)
34+
}
2235

23-
// 3. save proxies to file
24-
console.log('-> √ All proxies started!')
36+
// 3. save proxies to file
37+
console.log('-> √ All proxies started!')
38+
}
2539

2640
// 4. pm2 status
27-
execSync('pm2 status')
41+
execSync('pm2 logs')

0 commit comments

Comments
 (0)