Skip to content

Commit

Permalink
Support hosting below root
Browse files Browse the repository at this point in the history
  • Loading branch information
havfo committed Mar 15, 2024
1 parent fae3891 commit af5b08e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { startListeners, stopListeners } from './store/actions/startActions';
import {
useAppDispatch,
useAppSelector,
usePermissionSelector
} from './store/hooks';
import { useAppDispatch, useAppSelector, usePermissionSelector } from './store/hooks';
import StyledBackground from './components/StyledBackground';
import Join from './views/join/Join';
import Lobby from './views/lobby/Lobby';
Expand Down Expand Up @@ -81,19 +77,15 @@ const App = (): JSX.Element => {
*/
useEffect(() => {
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl')
|| canvas.getContext('experimental-webgl');
// Report the result.
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');

if (gl && gl instanceof WebGLRenderingContext) {
dispatch(meActions.setWebGLSupport(true));
}
}, []);

return (
<SnackbarProvider action={
(snackbarKey: SnackbarKey) => <SnackbarCloseButton snackbarKey={snackbarKey} />
}>
<SnackbarProvider action={ (snackbarKey: SnackbarKey) => <SnackbarCloseButton snackbarKey={snackbarKey} /> }>
<StyledBackground
onDrop={handleFileDrop}
onDragOver={(event) => event.preventDefault()}
Expand All @@ -105,4 +97,4 @@ const App = (): JSX.Element => {
);
};

export default App;
export default App;
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ const device = deviceInfo();
const unsupportedBrowser = !browserInfo.satisfies(supportedBrowsers);
const webrtcUnavailable = !navigator.mediaDevices || !navigator.mediaDevices.getUserMedia || !window.RTCPeerConnection;

// Detect the base url we are hosted on
const basename = window.location.pathname.split('/')
.slice(0, -1)
.join('/');

logger.debug('Starting app [baseUrl:%s]', basename);

const router = createBrowserRouter(
createRoutesFromElements(
<>
<Route path='/' element={<Suspense><LandingPage /></Suspense>} errorElement={<Suspense><ErrorBoundary /></Suspense>} />
<Route path='/:id' element={<Suspense><App /></Suspense>} errorElement={<Suspense><ErrorBoundary /></Suspense>} />
</>
)
), { basename }
);

/**
Expand Down

0 comments on commit af5b08e

Please sign in to comment.