]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16045 Fix routing with baseUrl
authorJeremy Davis <jeremy.davis@sonarsource.com>
Thu, 30 Jun 2022 13:21:42 +0000 (15:21 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 30 Jun 2022 20:03:10 +0000 (20:03 +0000)
server/sonar-web/src/main/js/app/components/PluginRiskConsent.tsx
server/sonar-web/src/main/js/app/components/ResetPassword.tsx
server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.tsx
server/sonar-web/src/main/js/app/utils/handleRequiredAuthorization.ts
server/sonar-web/src/main/js/app/utils/startReactApp.tsx
server/sonar-web/src/main/js/helpers/handleRequiredAuthentication.ts
server/sonar-web/src/main/js/helpers/urls.ts

index 9445a72706fd0735b935715fa211b15e75907555..1de2edd1a28863aa5b7bc0defc521e5d6fc5fa18 100644 (file)
@@ -23,6 +23,7 @@ import { Button } from '../../components/controls/buttons';
 import { whenLoggedIn } from '../../components/hoc/whenLoggedIn';
 import { Router, withRouter } from '../../components/hoc/withRouter';
 import { translate } from '../../helpers/l10n';
+import { getBaseUrl } from '../../helpers/system';
 import { hasGlobalPermission } from '../../helpers/users';
 import { Permissions } from '../../types/permissions';
 import { RiskConsent } from '../../types/plugins';
@@ -57,7 +58,8 @@ export function PluginRiskConsent(props: PluginRiskConsentProps) {
         value: RiskConsent.Accepted
       });
 
-      window.location.href = `/`; // force a refresh for the backend
+      // force a refresh for the backend
+      window.location.href = `${getBaseUrl()}/`;
     } catch (_) {
       /* Do nothing */
     }
index 1bb9f1db4c3df13f4ba45c4edef44a909e6d0702..6db3e0f0c8fc04555e161d01e9dd4622e12b18f1 100644 (file)
@@ -44,7 +44,7 @@ export function ResetPassword({ currentUser }: ResetPasswordProps) {
             user={currentUser}
             onPasswordChange={() => {
               // Force a refresh for the backend to handle additional redirects.
-              window.location.href = getBaseUrl() + '/';
+              window.location.href = `${getBaseUrl()}/`;
             }}
           />
         </div>
index 3a74eb08d06c84ad373b31d02b389bd445ffac35..b56309057c0b55e8104937d1491efca5a52796ce 100644 (file)
@@ -36,8 +36,9 @@ export class GlobalNavUser extends React.PureComponent<Props> {
   handleLogin = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
     event.preventDefault();
     const returnTo = encodeURIComponent(window.location.pathname + window.location.search);
-    window.location.href =
-      getBaseUrl() + `/sessions/new?return_to=${returnTo}${window.location.hash}`;
+    window.location.href = `${getBaseUrl()}/sessions/new?return_to=${returnTo}${
+      window.location.hash
+    }`;
   };
 
   handleLogout = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
index fd1ec8cca5c0ee326ccf8fe26a218b1195f43a31..934d1136bedc5dd983386ce49612b3a33fad9160 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+import { getBaseUrl } from '../../helpers/system';
+
 export default function handleRequiredAuthorization() {
   const returnTo = window.location.pathname + window.location.search + window.location.hash;
   const searchParams = new URLSearchParams({ return_to: returnTo, authorizationError: 'true' });
-  window.location.replace(`/sessions/new?${searchParams.toString()}`);
+  window.location.replace(`${getBaseUrl()}/sessions/new?${searchParams.toString()}`);
 }
index ace3ec81bd5f4848c03319973664b656313ef93d..b5387cfa9ec3a30321f83d4f05ba75baf113eb49 100644 (file)
@@ -59,6 +59,7 @@ import usersRoutes from '../../apps/users/routes';
 import webAPIRoutes from '../../apps/web-api/routes';
 import webhooksRoutes from '../../apps/webhooks/routes';
 import { omitNil } from '../../helpers/request';
+import { getBaseUrl } from '../../helpers/system';
 import { AppState } from '../../types/appstate';
 import { CurrentUser } from '../../types/users';
 import AdminContainer from '../components/AdminContainer';
@@ -233,7 +234,7 @@ export default function startReactApp(lang: string, appState: AppState, currentU
         <CurrentUserContextProvider currentUser={currentUser}>
           <IntlProvider defaultLocale={lang} locale={lang}>
             <GlobalMessagesContainer />
-            <BrowserRouter>
+            <BrowserRouter basename={getBaseUrl()}>
               <Routes>
                 {renderRedirects()}
 
index fbf9c5685513234c18774a5c4bb7849e1cb11c65..a1d2e3322f4d95551572502fc25efe89ece10454 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+import { getBaseUrl } from './system';
+
 export default function handleRequiredAuthentication() {
   const returnTo = window.location.pathname + window.location.search + window.location.hash;
   const searchParams = new URLSearchParams({ return_to: returnTo });
-  window.location.replace(`/sessions/new?${searchParams.toString()}`);
+  window.location.replace(`${getBaseUrl()}/sessions/new?${searchParams.toString()}`);
 }
index 6dbf21e8d9ed59ff466c04b2610ce2c2d4d39efa..d6e71bead373121f67385f88c99c898b4a8a7c1d 100644 (file)
@@ -424,7 +424,7 @@ export function getReturnUrl(location: { hash?: string; query?: { return_to?: st
   if (isRelativeUrl(returnTo)) {
     return returnTo + (location.hash ? location.hash : '');
   }
-  return getBaseUrl() + '/';
+  return `${getBaseUrl()}/`;
 }
 
 export function isRelativeUrl(url?: string): boolean {