refactor: add prefix to relative assets

refactor: add prefix to server entrypoints
refactor: add prefix to express router
refactor: add prefix to router basename
This commit is contained in:
Carlos Valente
2024-12-02 15:49:28 +01:00
committed by Carlos Valente
parent b3ce247f54
commit b9ba416366
8 changed files with 86 additions and 60 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ import { connectSocket } from './common/utils/socket';
import theme from './theme/theme';
import { TranslationProvider } from './translation/TranslationProvider';
import AppRouter from './AppRouter';
import { baseURI } from './externals';
connectSocket();
@@ -19,7 +20,7 @@ function App() {
<ChakraProvider disableGlobalStyle resetCSS theme={theme}>
<QueryClientProvider client={ontimeQueryClient}>
<AppContextProvider>
<BrowserRouter>
<BrowserRouter basename={baseURI}>
<div className='App'>
<ErrorBoundary>
<TranslationProvider>
+21 -3
View File
@@ -22,7 +22,25 @@ export const isOntimeCloud = Boolean(import.meta.env.VITE_IS_CLOUD);
const socketProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
// resolve port
const STATIC_PORT = 4001;
const STATIC_PORT = 4001; // this is used as a fallback port for development
export const serverPort = isProduction ? window.location.port : STATIC_PORT;
export const serverURL = `${window.location.protocol}//${location.hostname}:${serverPort}`;
export const websocketUrl = `${socketProtocol}://${location.hostname}:${serverPort}/ws`;
export const baseURI = resolveBaseURI();
export const serverURL = `${window.location.protocol}//${window.location.hostname}:${serverPort}${baseURI}`;
export const websocketUrl = `${socketProtocol}://${window.location.hostname}:${serverPort}${baseURI}/ws`;
/**
* Resolves a base URI for a client that is not at the root segment
* ie: https://cloud.getontime.com/client-hash/timer
* This is necessary for ontime cloud and should otherwise not affect the client
*/
function resolveBaseURI() {
if (!isOntimeCloud) {
return '';
}
const [_, base, location] = window.location.pathname.split('/');
if (!location) {
return '';
}
return `/${base}`;
}