mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
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:
committed by
Carlos Valente
parent
b3ce247f54
commit
b9ba416366
@@ -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>
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user