Skip to content

Commit 8a92a46

Browse files
committed
chore: give ability to change endpoint per project
1 parent 312ba54 commit 8a92a46

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

templates/cli/lib/commands/init.js.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
9494
}
9595
}
9696

97+
// Handle endpoint prompt after project selection
98+
if (answers.endpoint) {
99+
globalConfig.setEndpoint(answers.endpoint);
100+
}
101+
97102
if (answers.start === 'new') {
98103
response = await projectsCreate({
99104
projectId: answers.id,

templates/cli/lib/questions.js.twig

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,35 @@ const questionsInitProject = [
207207
}
208208
})
209209

210-
if (choices.length == 0) {
210+
if (choices.length === 0) {
211211
throw new Error("No projects found. Please create a new project.")
212212
}
213213

214214
return choices;
215215
},
216216
when: (answer) => answer.start === 'existing'
217+
},
218+
{
219+
type: "input",
220+
name: "endpoint",
221+
message: "Enter the endpoint of your {{ spec.title|caseUcfirst }} server",
222+
default: () => globalConfig.getEndpoint() || "https://cloud.appwrite.io/v1",
223+
async validate(value) {
224+
if (!value) {
225+
return "Please enter a valid endpoint.";
226+
}
227+
let client = new Client().setEndpoint(value);
228+
try {
229+
let response = await client.call('get', '/health/version');
230+
if (response.version) {
231+
return true;
232+
} else {
233+
throw new Error();
234+
}
235+
} catch (error) {
236+
return "Invalid endpoint or your Appwrite server is not running as expected.";
237+
}
238+
}
217239
}
218240
];
219241
const questionsInitProjectAutopull = [

0 commit comments

Comments
 (0)