From d9c6553b440beea19871842805df4a92fcbcb113 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Tue, 9 May 2023 16:26:11 -0700 Subject: [PATCH] env-specific search endpoint --- src/lib/api/search.ts | 12 +++++++----- src/lib/constants.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lib/api/search.ts b/src/lib/api/search.ts index dfe9b688b9..589c5592c4 100644 --- a/src/lib/api/search.ts +++ b/src/lib/api/search.ts @@ -3,9 +3,7 @@ * TODO removeme when we land this in proto! */ import {AppBskyFeedPost} from '@atproto/api' - -const PROFILES_ENDPOINT = 'https://search.bsky.social/search/profiles' -const POSTS_ENDPOINT = 'https://search.bsky.social/search/posts' +import {SEARCH_HOST} from 'lib/constants' export interface ProfileSearchItem { $type: string @@ -35,11 +33,15 @@ export interface PostSearchItem { export async function searchProfiles( query: string, ): Promise { - return await doFetch(PROFILES_ENDPOINT, query) + const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '') + const endpoint = `${host}/search/profiles` + return await doFetch(endpoint, query) } export async function searchPosts(query: string): Promise { - return await doFetch(POSTS_ENDPOINT, query) + const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '') + const endpoint = `${host}/search/posts` + return await doFetch(endpoint, query) } async function doFetch(endpoint: string, query: string): Promise { diff --git a/src/lib/constants.ts b/src/lib/constants.ts index df325b059b..4c97868e96 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -86,6 +86,16 @@ export function SUGGESTED_FOLLOWS(serviceUrl: string) { } } +export function SEARCH_HOST(serviceUrl: string) { + if (serviceUrl.includes('localhost')) { + return 'http://localhost:2470' + } else if (serviceUrl.includes('staging.bsky.dev')) { + return 'https://search.staging.bsky.dev' + } else { + return 'https://search.bsky.social' + } +} + export const POST_IMG_MAX = { width: 2000, height: 2000,