Skip to content

Commit fbd1b79

Browse files
authored
fix(cli): use correct subpath during setup slack app for self hosted (#280)
1 parent f79a685 commit fbd1b79

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

packages/blink/src/cli/setup-slack-app.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "./lib/in-memory-cli";
1212
import { makeTmpDir } from "./lib/terminal";
1313
import {
14+
appendSubpath,
1415
setupSlackApp,
1516
updateEnvCredentials,
1617
verifySlackSignature,
@@ -111,6 +112,44 @@ describe("verifySlackSignature", () => {
111112
});
112113
});
113114

115+
describe("appendSubpath", () => {
116+
it("should append a subpath to a simple URL", () => {
117+
expect(appendSubpath("https://example.com", "/slack")).toBe(
118+
"https://example.com/slack"
119+
);
120+
});
121+
122+
it("should append a subpath to a URL with an existing path", () => {
123+
expect(appendSubpath("https://example.com/devhook/abc", "/slack")).toBe(
124+
"https://example.com/devhook/abc/slack"
125+
);
126+
});
127+
128+
it("should handle trailing slashes on the base URL", () => {
129+
expect(appendSubpath("https://example.com/devhook/", "/slack")).toBe(
130+
"https://example.com/devhook/slack"
131+
);
132+
});
133+
134+
it("should handle subpath without leading slash", () => {
135+
expect(appendSubpath("https://example.com/devhook", "slack")).toBe(
136+
"https://example.com/devhook/slack"
137+
);
138+
});
139+
140+
it("should handle both trailing and leading slashes", () => {
141+
expect(appendSubpath("https://example.com/devhook///", "///slack")).toBe(
142+
"https://example.com/devhook/slack"
143+
);
144+
});
145+
146+
it("should preserve query parameters", () => {
147+
expect(
148+
appendSubpath("https://example.com/devhook?token=abc", "/slack")
149+
).toBe("https://example.com/devhook/slack?token=abc");
150+
});
151+
});
152+
114153
describe("updateEnvCredentials", () => {
115154
it("should add credentials to an empty env file", async () => {
116155
await using tempDir = await makeTmpDir();

packages/blink/src/cli/setup-slack-app.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export function verifySlackSignature(
9797
);
9898
}
9999

100+
export function appendSubpath(baseUrl: string, subpath: string): string {
101+
const url = new URL(baseUrl);
102+
url.pathname = `${url.pathname.replace(/\/+$/, "")}/${subpath.replace(/^\/+/, "")}`;
103+
return url.toString();
104+
}
105+
100106
const makeDisposable = (value: unknown): Disposable => {
101107
if (!(typeof value === "object" && value !== null)) {
102108
throw new Error("Unable to make value disposable, it's not an object");
@@ -234,7 +240,10 @@ export async function setupSlackApp(
234240
baseURL: host,
235241
authToken: getAuthToken(),
236242
});
237-
const webhookUrl = await client.devhook.getUrl(devhookId);
243+
const webhookUrl = appendSubpath(
244+
await client.devhook.getUrl(devhookId),
245+
"/slack"
246+
);
238247

239248
log.info("Starting webhook listener...");
240249

0 commit comments

Comments
 (0)