Skip to content

Commit 15e4aa1

Browse files
fix(web): Use AUTH_URL when generating external links (#844)
1 parent 4f04e7f commit 15e4aa1

File tree

7 files changed

+14
-50
lines changed

7 files changed

+14
-50
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Fixed issue where external links would use internal service DNS names in k8s deployments, making them inaccessible. [#844](https://github.com/sourcebot-dev/sourcebot/pull/844)
12+
1013
## [4.10.23] - 2026-02-02
1114

1215
### Added

packages/web/src/actions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type";
1717
import { GitlabConnectionConfig } from "@sourcebot/schemas/v3/gitlab.type";
1818
import { getPlan, hasEntitlement } from "@sourcebot/shared";
1919
import { StatusCodes } from "http-status-codes";
20-
import { cookies, headers } from "next/headers";
20+
import { cookies } from "next/headers";
2121
import { createTransport } from "nodemailer";
2222
import { Octokit } from "octokit";
2323
import { auth } from "./auth";
@@ -31,7 +31,6 @@ import { AGENTIC_SEARCH_TUTORIAL_DISMISSED_COOKIE_NAME, MOBILE_UNSUPPORTED_SPLAS
3131
import { orgDomainSchema, orgNameSchema, repositoryQuerySchema } from "./lib/schemas";
3232
import { ApiKeyPayload, TenancyMode } from "./lib/types";
3333
import { withAuthV2, withOptionalAuthV2 } from "./withAuthV2";
34-
import { getBaseUrl } from "./lib/utils.server";
3534
import { getBrowsePath } from "./app/[domain]/browse/hooks/utils";
3635

3736
const logger = createLogger('web-actions');
@@ -478,8 +477,7 @@ export const getRepos = async ({
478477
take,
479478
});
480479

481-
const headersList = await headers();
482-
const baseUrl = getBaseUrl(headersList);
480+
const baseUrl = env.AUTH_URL;
483481

484482
return repos.map((repo) => repositoryQuerySchema.parse({
485483
codeHostType: repo.external_codeHostType,
@@ -893,7 +891,6 @@ export const createInvites = async (emails: string[], domain: string): Promise<{
893891

894892
// Send invites to recipients
895893
if (env.SMTP_CONNECTION_URL && env.EMAIL_FROM_ADDRESS) {
896-
const origin = (await headers()).get('origin')!;
897894
await Promise.all(emails.map(async (email) => {
898895
const invite = await prisma.invite.findUnique({
899896
where: {
@@ -916,7 +913,7 @@ export const createInvites = async (emails: string[], domain: string): Promise<{
916913
email,
917914
},
918915
});
919-
const inviteLink = `${origin}/redeem?invite_id=${invite.id}`;
916+
const inviteLink = `${env.AUTH_URL}/redeem?invite_id=${invite.id}`;
920917
const transport = createTransport(env.SMTP_CONNECTION_URL);
921918
const html = await render(InviteUserEmail({
922919
host: {
@@ -1585,10 +1582,8 @@ export const approveAccountRequest = async (requestId: string, domain: string) =
15851582

15861583
// Send approval email to the user
15871584
if (env.SMTP_CONNECTION_URL && env.EMAIL_FROM_ADDRESS) {
1588-
const origin = (await headers()).get('origin')!;
1589-
15901585
const html = await render(JoinRequestApprovedEmail({
1591-
baseUrl: origin,
1586+
baseUrl: env.AUTH_URL,
15921587
user: {
15931588
name: request.requestedBy.name ?? undefined,
15941589
email: request.requestedBy.email!,

packages/web/src/app/api/(server)/chat/blocking/route.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import { convertLLMOutputToPortableMarkdown, getAnswerPartFromAssistantMessage,
55
import { ErrorCode } from "@/lib/errorCodes";
66
import { requestBodySchemaValidationError, ServiceError, ServiceErrorException, serviceErrorResponse } from "@/lib/serviceError";
77
import { isServiceError } from "@/lib/utils";
8-
import { getBaseUrl } from "@/lib/utils.server";
98
import { withOptionalAuthV2 } from "@/withAuthV2";
109
import { ChatVisibility, Prisma } from "@sourcebot/db";
11-
import { createLogger } from "@sourcebot/shared";
10+
import { createLogger, env } from "@sourcebot/shared";
1211
import { randomUUID } from "crypto";
1312
import { StatusCodes } from "http-status-codes";
14-
import { headers } from "next/headers";
1513
import { NextRequest, NextResponse } from "next/server";
1614
import { z } from "zod";
1715
import { createMessageStream } from "../route";
@@ -188,8 +186,7 @@ export const POST = apiHandler(async (request: NextRequest) => {
188186
const portableAnswer = convertLLMOutputToPortableMarkdown(answerText);
189187

190188
// Build the chat URL
191-
const headersList = await headers();
192-
const baseUrl = getBaseUrl(headersList);
189+
const baseUrl = env.AUTH_URL;
193190
const chatUrl = `${baseUrl}/${org.domain}/chat/${chat.id}`;
194191

195192
logger.debug(`Completed blocking agent for chat ${chat.id}`, {

packages/web/src/app/api/(server)/repos/listReposApi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import { sew } from "@/actions";
22
import { repositoryQuerySchema } from "@/lib/schemas";
33
import { ListReposQueryParams } from "@/lib/types";
44
import { withOptionalAuthV2 } from "@/withAuthV2";
5-
import { headers } from "next/headers";
6-
import { getBaseUrl } from "@/lib/utils.server";
75
import { getBrowsePath } from "@/app/[domain]/browse/hooks/utils";
6+
import { env } from "@sourcebot/shared";
87

98
export const listRepos = async ({ query, page, perPage, sort, direction }: ListReposQueryParams) => sew(() =>
109
withOptionalAuthV2(async ({ org, prisma }) => {
1110
const skip = (page - 1) * perPage;
1211
const orderByField = sort === 'pushed' ? 'pushedAt' : 'name';
13-
14-
const headersList = await headers();
15-
const baseUrl = getBaseUrl(headersList);
12+
const baseUrl = env.AUTH_URL;
1613

1714
const [repos, totalCount] = await Promise.all([
1815
prisma.repo.findMany({

packages/web/src/app/components/organizationAccessSettings.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { createInviteLink } from "@/lib/utils"
2-
import { getBaseUrl } from "@/lib/utils.server"
32
import { AnonymousAccessToggle } from "./anonymousAccessToggle"
43
import { OrganizationAccessSettingsWrapper } from "./organizationAccessSettingsWrapper"
54
import { getOrgFromDomain } from "@/data/org"
65
import { getOrgMetadata } from "@/lib/utils"
7-
import { headers } from "next/headers"
86
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
9-
import { hasEntitlement } from "@sourcebot/shared"
10-
import { env } from "@sourcebot/shared"
7+
import { hasEntitlement, env } from "@sourcebot/shared"
118

129
export async function OrganizationAccessSettings() {
1310
const org = await getOrgFromDomain(SINGLE_TENANT_ORG_DOMAIN);
@@ -18,8 +15,7 @@ export async function OrganizationAccessSettings() {
1815
const metadata = getOrgMetadata(org);
1916
const anonymousAccessEnabled = metadata?.anonymousAccessEnabled ?? false;
2017

21-
const headersList = await headers();
22-
const baseUrl = getBaseUrl(headersList);
18+
const baseUrl = env.AUTH_URL;
2319
const inviteLink = createInviteLink(baseUrl, org.inviteLinkId)
2420

2521
const hasAnonymousAccessEntitlement = hasEntitlement("anonymous-access");

packages/web/src/features/search/zoektSearcher.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { RepositoryInfo, SearchResponse, SearchResultFile, SearchStats, SourceRa
2020
import { captureEvent } from "@/lib/posthog";
2121
import { getBrowsePath } from "@/app/[domain]/browse/hooks/utils";
2222
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
23-
import { headers } from "next/headers";
24-
import { getBaseUrl } from "@/lib/utils.server";
2523

2624
const logger = createLogger("zoekt-searcher");
2725

@@ -383,9 +381,6 @@ const transformZoektSearchResponse = async (response: ZoektGrpcSearchResponse, r
383381
files: SearchResultFile[],
384382
repositoryInfo: RepositoryInfo[],
385383
}> => {
386-
const headersList = await headers();
387-
const baseUrl = getBaseUrl(headersList);
388-
389384
const files = response.files.map((file) => {
390385
const fileNameChunks = file.chunk_matches.filter((chunk) => chunk.file_name);
391386
const repoId = getRepoIdForFile(file);
@@ -431,7 +426,7 @@ const transformZoektSearchResponse = async (response: ZoektGrpcSearchResponse, r
431426
repository: repo.name,
432427
repositoryId: repo.id,
433428
language: file.language,
434-
webUrl: `${baseUrl}${getBrowsePath({
429+
webUrl: `${env.AUTH_URL}${getBrowsePath({
435430
repoName: repo.name,
436431
path: fileName,
437432
pathType: 'blob',

packages/web/src/lib/utils.server.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)