1
1
// 1. read proxies from file
2
2
const fs = require ( 'fs' )
3
3
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
+ }
5
12
6
13
// 2. start pm2 with PROXY env
7
14
const { execSync } = require ( 'child_process' )
@@ -13,15 +20,22 @@ if (!USER || !PASSWORD) {
13
20
process . exit ( )
14
21
}
15
22
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
+ }
22
35
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
+ }
25
39
26
40
// 4. pm2 status
27
- execSync ( 'pm2 status ' )
41
+ execSync ( 'pm2 logs ' )
0 commit comments