Merge branch 'baseurl' into 'main'

Fix baseURL drama

See merge request soapbox-pub/soapbox!3299
This commit is contained in:
Alex Gleason 2024-12-14 02:19:05 +00:00
commit 98617d1036
3 changed files with 8 additions and 7 deletions

View File

@ -33,7 +33,7 @@ const fetchFrontendConfigurations = () =>
(dispatch: AppDispatch, getState: () => RootState) => (dispatch: AppDispatch, getState: () => RootState) =>
api(getState) api(getState)
.get('/api/pleroma/frontend_configurations') .get('/api/pleroma/frontend_configurations')
.then((response) => response.json()).then((data) => data); .then((response) => response.json());
/** Conditionally fetches Soapbox config depending on backend features */ /** Conditionally fetches Soapbox config depending on backend features */
const fetchSoapboxConfig = (host: string | null = null) => const fetchSoapboxConfig = (host: string | null = null) =>
@ -41,7 +41,7 @@ const fetchSoapboxConfig = (host: string | null = null) =>
const features = getFeatures(getState().instance); const features = getFeatures(getState().instance);
if (features.frontendConfigurations) { if (features.frontendConfigurations) {
return dispatch(fetchFrontendConfigurations()).then(data => { return dispatch(fetchFrontendConfigurations()).then((data) => {
if (data.soapbox_fe) { if (data.soapbox_fe) {
dispatch(importSoapboxConfig(data.soapbox_fe, host)); dispatch(importSoapboxConfig(data.soapbox_fe, host));
return data.soapbox_fe; return data.soapbox_fe;

View File

@ -1,6 +1,7 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { MastodonClient } from 'soapbox/api/MastodonClient.ts'; import { MastodonClient } from 'soapbox/api/MastodonClient.ts';
import * as BuildConfig from 'soapbox/build-config.ts';
import { selectAccount } from 'soapbox/selectors/index.ts'; import { selectAccount } from 'soapbox/selectors/index.ts';
import { RootState } from 'soapbox/store.ts'; import { RootState } from 'soapbox/store.ts';
import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth.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) => me ? selectAccount(state, me)?.url : undefined,
(state: RootState, _me: string | false | null) => state.auth.me, (state: RootState, _me: string | false | null) => state.auth.me,
], (accountUrl, authUserUrl) => { ], (accountUrl, authUserUrl) => {
const baseURL = parseBaseURL(accountUrl) || parseBaseURL(authUserUrl); return parseBaseURL(accountUrl) || parseBaseURL(authUserUrl);
return baseURL !== window.location.origin ? baseURL : '';
}); });
/** Base client for HTTP requests. */ /** Base client for HTTP requests. */
export const baseClient = ( export const baseClient = (
accessToken?: string | null, accessToken?: string | null,
baseURL: string = '', baseURL: string = location.origin,
): MastodonClient => { ): MastodonClient => {
return new MastodonClient(baseURL, accessToken || undefined); return new MastodonClient(baseURL, accessToken || undefined);
}; };
@ -33,7 +33,7 @@ export default (getState: () => RootState, authType: string = 'user'): MastodonC
const state = getState(); const state = getState();
const accessToken = getToken(state, authType); const accessToken = getToken(state, authType);
const me = state.me; 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); return baseClient(accessToken, baseURL);
}; };

View File

@ -75,7 +75,8 @@ const SoapboxLoad: React.FC<ISoapboxLoad> = ({ children }) => {
if (!instance.isLoading && !nostrLoading) { if (!instance.isLoading && !nostrLoading) {
dispatch(loadInitial()).then(() => { dispatch(loadInitial()).then(() => {
setIsLoaded(true); setIsLoaded(true);
}).catch(() => { }).catch((error) => {
console.error(error);
setIsLoaded(true); setIsLoaded(true);
}); });
} }