Skip to content

Commit d47763a

Browse files
committed
validate endpoint on login
1 parent 4a3cf9a commit d47763a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

templates/cli/lib/sdks.js.twig

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ const questionGetEndpoint = [
77
type: "input",
88
name: "endpoint",
99
message: "Enter the endpoint of your {{ spec.title|caseUcfirst }} server",
10-
default: "http://localhost/v1"
10+
default: "http://localhost/v1",
11+
validate: async (value) => {
12+
if(!value) {
13+
return 'Please provide valid endpoint';
14+
}
15+
let client = new Client().setEndpoint(value);
16+
try {
17+
let response = await client.call('GET', '/mock/tests/foo', {}, {'x': 'a', 'y': 1, 'z': ['a']});
18+
if(response.result && response.result === 'GET:/v1/mock/tests/foo:passed') {
19+
return true;
20+
} else {
21+
return 'Not a valid endpoint or Appwrite server is not running as expected';
22+
}
23+
} catch (error) {
24+
return 'Not a valid endpoint or Appwrite server is not running as expected';
25+
}
26+
return true;
27+
}
1128
}
1229
]
1330

0 commit comments

Comments
 (0)