From 4b3e8fcf22122e040a3dbdb56dad631154c2d502 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 13 Dec 2024 20:18:05 -0600 Subject: [PATCH] Fix baseURL drama --- src/actions/soapbox.ts | 4 ++-- src/api/index.ts | 8 ++++---- src/init/soapbox-load.tsx | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/actions/soapbox.ts b/src/actions/soapbox.ts index d53fabbf7..b01c089f1 100644 --- a/src/actions/soapbox.ts +++ b/src/actions/soapbox.ts @@ -33,7 +33,7 @@ const fetchFrontendConfigurations = () => (dispatch: AppDispatch, getState: () => RootState) => api(getState) .get('/api/pleroma/frontend_configurations') - .then((response) => response.json()).then((data) => data); + .then((response) => response.json()); /** Conditionally fetches Soapbox config depending on backend features */ const fetchSoapboxConfig = (host: string | null = null) => @@ -41,7 +41,7 @@ const fetchSoapboxConfig = (host: string | null = null) => const features = getFeatures(getState().instance); if (features.frontendConfigurations) { - return dispatch(fetchFrontendConfigurations()).then(data => { + return dispatch(fetchFrontendConfigurations()).then((data) => { if (data.soapbox_fe) { dispatch(importSoapboxConfig(data.soapbox_fe, host)); return data.soapbox_fe; diff --git a/src/api/index.ts b/src/api/index.ts index f56fa9a4c..225b27d9e 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,7 @@ import { createSelector } from 'reselect'; import { MastodonClient } from 'soapbox/api/MastodonClient.ts'; +import * as BuildConfig from 'soapbox/build-config.ts'; import { selectAccount } from 'soapbox/selectors/index.ts'; import { RootState } from 'soapbox/store.ts'; import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth.ts'; @@ -13,14 +14,13 @@ const getAuthBaseURL = createSelector([ (state: RootState, me: string | false | null) => me ? selectAccount(state, me)?.url : undefined, (state: RootState, _me: string | false | null) => state.auth.me, ], (accountUrl, authUserUrl) => { - const baseURL = parseBaseURL(accountUrl) || parseBaseURL(authUserUrl); - return baseURL !== window.location.origin ? baseURL : ''; + return parseBaseURL(accountUrl) || parseBaseURL(authUserUrl); }); /** Base client for HTTP requests. */ export const baseClient = ( accessToken?: string | null, - baseURL: string = '', + baseURL: string = location.origin, ): MastodonClient => { return new MastodonClient(baseURL, accessToken || undefined); }; @@ -33,7 +33,7 @@ export default (getState: () => RootState, authType: string = 'user'): MastodonC const state = getState(); const accessToken = getToken(state, authType); const me = state.me; - const baseURL = me ? getAuthBaseURL(state, me) : ''; + const baseURL = BuildConfig.BACKEND_URL ?? (me ? getAuthBaseURL(state, me) : location.origin); return baseClient(accessToken, baseURL); }; diff --git a/src/init/soapbox-load.tsx b/src/init/soapbox-load.tsx index 2fddc0445..92c05cc74 100644 --- a/src/init/soapbox-load.tsx +++ b/src/init/soapbox-load.tsx @@ -75,7 +75,8 @@ const SoapboxLoad: React.FC = ({ children }) => { if (!instance.isLoading && !nostrLoading) { dispatch(loadInitial()).then(() => { setIsLoaded(true); - }).catch(() => { + }).catch((error) => { + console.error(error); setIsLoaded(true); }); }