Skip to content

Commit 3cd6969

Browse files
authored
Merge pull request #24 from tago-io/fix/tago-deploy
feat: enhance URL input handling in login command and update environm…
2 parents d2fb8fd + 89f68f9 commit 3cd6969

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/commands/analysis/run-analysis.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { SpawnOptions, spawn } from "node:child_process";
1+
import { spawn, SpawnOptions } from "node:child_process";
22
import path from "node:path";
33

44
import { Account } from "@tago-io/sdk";
55

6-
import { IEnvironment, getEnvironmentConfig, resolveCLIPath } from "../../lib/config-file";
6+
import { getEnvironmentConfig, IEnvironment, resolveCLIPath } from "../../lib/config-file";
77
import { getCurrentFolder } from "../../lib/get-current-folder";
88
import { errorHandler, highlightMSG, successMSG } from "../../lib/messages";
99
import { searchName } from "../../lib/search-name";
@@ -92,7 +92,9 @@ async function runAnalysis(scriptName: string | undefined, options: { environmen
9292
if (config.profileRegion.realtime) {
9393
analysisEnv.TAGOIO_REALTIME = config.profileRegion.realtime;
9494
}
95-
// analysisEnv.TAGOIO_SSE = config.profileRegion.sse;
95+
if (config.profileRegion.sse) {
96+
analysisEnv.TAGOIO_SSE = config.profileRegion.sse;
97+
}
9698
}
9799

98100
const spawnOptions: SpawnOptions = {

src/commands/login.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import prompts from "prompts";
33
import { Account } from "@tago-io/sdk";
44
import { OTPType } from "@tago-io/sdk/lib/types";
55

6+
import { addHttpsToUrl } from "../lib/add-https-to-url";
67
import { errorHandler, highlightMSG, successMSG } from "../lib/messages";
78
import { writeToken } from "../lib/token";
89

@@ -19,24 +20,34 @@ async function getTagoDeployURL(): Promise<{ urlAPI: string; urlSSE: string } |
1920
return;
2021
}
2122

22-
const { urlAPI } = await prompts({ type: "text", name: "urlAPI", message: "Set the URL for the API service: ", hint: "https://api.tago.io" });
23+
let { urlAPI } = await prompts({ type: "text", name: "urlAPI", message: "Set the URL for the API service: ", hint: "https://api.tago.io" });
2324
if (!urlAPI) {
2425
return;
2526
}
2627

28+
urlAPI = addHttpsToUrl(urlAPI);
29+
2730
const sanitizedUrlAPI = new URL(urlAPI).origin;
2831

2932
let { urlSSE } = await prompts({ type: "text", name: "urlSSE", message: "Set the URL for the SSE service: ", hint: "https://sse.tago.io" });
33+
34+
urlSSE = addHttpsToUrl(urlSSE);
35+
3036
if (!urlSSE) {
3137
urlSSE = sanitizedUrlAPI.replace("https://api.", "https://sse.");
3238
}
3339

3440
if (urlSSE) {
41+
urlSSE = urlSSE.replace("api.", "sse.");
42+
3543
const sseUrl = new URL(urlSSE);
3644
sseUrl.pathname = '/events';
3745
urlSSE = sseUrl.toString();
3846
}
3947

48+
process.env.TAGOIO_API = sanitizedUrlAPI;
49+
process.env.TAGOIO_SSE = urlSSE;
50+
4051
return { urlAPI: sanitizedUrlAPI, urlSSE };
4152
}
4253

src/commands/start-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Account } from "@tago-io/sdk";
77
import { GenericModuleParams } from "@tago-io/sdk/lib/common/TagoIOModule";
88
import { AnalysisInfo, AnalysisListItem } from "@tago-io/sdk/lib/types";
99

10-
import { IEnvironment, getConfigFile, writeConfigFileEnv, writeToConfigFile } from "../lib/config-file";
10+
import { getConfigFile, IEnvironment, writeConfigFileEnv, writeToConfigFile } from "../lib/config-file";
1111
import { errorHandler, highlightMSG, infoMSG } from "../lib/messages";
1212
import { readToken, writeToken } from "../lib/token";
1313
import { promptTextToEnter } from "../prompt/text-prompt";
@@ -179,6 +179,9 @@ async function startConfig(environment: string, { token }: ConfigOptions) {
179179
}
180180

181181
let tagoAPIURL, tagoSSEURL: string | undefined;
182+
183+
184+
182185
// Get token from file or prompt user to create one
183186
if (!token) {
184187
token = readToken(environment);
@@ -187,6 +190,9 @@ async function startConfig(environment: string, { token }: ConfigOptions) {
187190
token = data?.profileToken;
188191
tagoAPIURL = data?.tagoDeployUrl;
189192
tagoSSEURL = data?.tagoDeploySse;
193+
} else {
194+
tagoAPIURL = configFile[environment]?.tagoAPIURL;
195+
tagoSSEURL = configFile[environment]?.tagoSSEURL;
190196
}
191197
} else {
192198
const urlConfig = await getTagoDeployURL()

src/lib/add-https-to-url.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Add https to the url if it doesn't have it
3+
* If the url is already https, return the url
4+
* @param url - The url to add https to
5+
* @returns The url with https
6+
*/
7+
function addHttpsToUrl(url: string): string {
8+
if (!url) {
9+
return "";
10+
}
11+
12+
if (!url.startsWith("https://")) {
13+
return `https://${url}`;
14+
}
15+
return url;
16+
}
17+
18+
export { addHttpsToUrl };

0 commit comments

Comments
 (0)