Skip to content

Commit b445c01

Browse files
committed
chore: use spec.endpoint consistently
1 parent a6bcc45 commit b445c01

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ID = require("../id");
99
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
1010
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
1111

12-
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
12+
const DEFAULT_ENDPOINT = '{{ spec.endpoint }}';
1313

1414
const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
1515
const oldCurrent = globalConfig.getCurrentSession();

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
9595
}
9696
}
9797

98+
localConfig.clear(); // Clear the config to avoid any conflicts
99+
const url = new URL("{{ spec.endpoint }}");
100+
98101
if (answers.start === 'new') {
99-
localConfig.clear();
100102
response = await projectsCreate({
101103
projectId: answers.id,
102104
name: answers.project,
@@ -105,16 +107,13 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
105107
})
106108

107109
localConfig.setProject(response['$id']);
108-
109110
if (answers.region) {
110-
const endpoint = `https://${answers.region}.cloud.appwrite.io/v1`;
111-
localConfig.setEndpoint(endpoint);
111+
localConfig.setEndpoint(`https://${answers.region}.${url.host}${url.pathname}`);
112112
}
113113
} else {
114114
localConfig.setProject(answers.project["$id"]);
115115
if(isCloud()) {
116-
const endpoint = `https://${answers.project["region"]}.cloud.appwrite.io/v1`;
117-
localConfig.setEndpoint(endpoint);
116+
localConfig.setEndpoint(`https://${answers.project["region"]}.${url.host}${url.pathname}`);
118117
}
119118
}
120119

templates/cli/lib/parser.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { description } = require('../package.json');
55
const { globalConfig } = require("./config.js");
66
const os = require('os');
77
const Client = require("./client");
8+
const { isCloud } = require("./utils");
89

910
const cliConfig = {
1011
verbose: false,
@@ -111,7 +112,6 @@ const parseError = (err) => {
111112
(async () => {
112113
let appwriteVersion = 'unknown';
113114
const endpoint = globalConfig.getEndpoint();
114-
const isCloud = endpoint.includes('cloud.appwrite.io') ? 'Yes' : 'No';
115115

116116
try {
117117
const client = new Client().setEndpoint(endpoint);
@@ -122,7 +122,7 @@ const parseError = (err) => {
122122

123123
const version = '{{ sdk.version }}';
124124
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
125-
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`;
125+
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;
126126

127127
const stack = '```\n' + err.stack + '\n```';
128128

templates/cli/lib/utils.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function getUsersPath(action, ids) {
275275
}
276276

277277
function isCloud() {
278-
const endpoint = globalConfig.getEndpoint() || "https://cloud.appwrite.io/v1";
278+
const endpoint = globalConfig.getEndpoint() || "{{ spec.endpoint }}";
279279
const hostname = new URL(endpoint).hostname;
280280
return hostname.endsWith('appwrite.io');
281281
}

0 commit comments

Comments
 (0)