File tree Expand file tree Collapse file tree 2 files changed +31
-12
lines changed
Expand file tree Collapse file tree 2 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -64,10 +64,24 @@ export async function dev() {
6464 const url = process . env . URL ?? "http://127.0.0.1:8080" ;
6565
6666 console . log ( c . cyan ( `Make sure app is running on ${ url } ` ) ) ;
67- try {
68- await await200 ( url ) ;
69- } catch {
70- throw new Error ( `Can't reach app on ${ url } ` ) ;
67+ let appRunning = false ;
68+
69+ while ( ! appRunning ) {
70+ try {
71+ await await200 ( url ) ;
72+ appRunning = true ;
73+ } catch {
74+ const { retry } = await enquirer . prompt ( {
75+ type : "confirm" ,
76+ name : "retry" ,
77+ initial : true ,
78+ message : `Can't reach app on ${ url } . Do you want to retry?`
79+ } ) ;
80+
81+ if ( ! retry ) {
82+ throw new Error ( `App is not running on ${ url } . Exiting.` ) ;
83+ }
84+ }
7185 }
7286
7387 console . log ( c . cyan ( "Launch Playwright" ) ) ;
Original file line number Diff line number Diff line change @@ -39,14 +39,19 @@ export async function fetchGithubRestAPI(url, init = {}) {
3939
4040export async function await200 ( url = "http://127.0.0.1:8080" , attempts = 50 ) {
4141 let n = 0 ;
42- while ( ++ n <= attempts ) {
43- console . log ( c . cyan ( `GET ${ url } ${ n } ` ) ) ;
44- const response = await fetch ( url ) ;
45- const { ok, status } = response ;
46-
47- if ( ok && status === 200 ) {
48- console . log ( c . green ( `200 OK, continue` ) ) ;
49- return ;
42+ while ( n < attempts ) {
43+ n ++ ;
44+ console . log ( c . cyan ( `GET ${ url } attempt ${ n } /${ attempts } ` ) ) ;
45+ try {
46+ const response = await fetch ( url ) ;
47+ const { ok, status } = response ;
48+
49+ if ( ok && status === 200 ) {
50+ console . log ( c . green ( `200 OK, continue` ) ) ;
51+ return ;
52+ }
53+ } catch ( error ) {
54+ console . error ( c . red ( `Error during fetch: ${ error . message } ` ) ) ;
5055 }
5156
5257 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
You can’t perform that action at this time.
0 commit comments