feat(ui): handle proxy configs rewriting paths

We can't assume that the base URL is `host:port/` - it could be `host:port/some/path/`. Make the path handling dynamic to account for this.
This commit is contained in:
psychedelicious 2024-01-24 12:03:09 +11:00
parent e59954f956
commit fc448d5b6d
4 changed files with 8 additions and 5 deletions

View File

@ -45,7 +45,7 @@ export const useSocketIO = () => {
const socketOptions = useMemo(() => { const socketOptions = useMemo(() => {
const options: Partial<ManagerOptions & SocketOptions> = { const options: Partial<ManagerOptions & SocketOptions> = {
timeout: 60000, timeout: 60000,
path: '/ws/socket.io', path: `${window.location.pathname}ws/socket.io`,
autoConnect: false, // achtung! removing this breaks the dynamic middleware autoConnect: false, // achtung! removing this breaks the dynamic middleware
forceNew: true, forceNew: true,
}; };

View File

@ -32,7 +32,7 @@ if (import.meta.env.MODE === 'package') {
fallbackLng: 'en', fallbackLng: 'en',
debug: false, debug: false,
backend: { backend: {
loadPath: '/locales/{{lng}}.json', loadPath: `${window.location.href.replace(/\/$/, '')}/locales/{{lng}}.json`,
}, },
interpolation: { interpolation: {
escapeValue: false, escapeValue: false,

View File

@ -57,7 +57,9 @@ const dynamicBaseQuery: BaseQueryFn<
const projectId = $projectId.get(); const projectId = $projectId.get();
const rawBaseQuery = fetchBaseQuery({ const rawBaseQuery = fetchBaseQuery({
baseUrl: `${baseUrl ?? ''}/api/v1`, baseUrl: baseUrl
? `${baseUrl}/api/v1`
: `${window.location.href.replace(/\/$/, '')}/api/v1`,
prepareHeaders: (headers) => { prepareHeaders: (headers) => {
if (authToken) { if (authToken) {
headers.set('Authorization', `Bearer ${authToken}`); headers.set('Authorization', `Bearer ${authToken}`);

View File

@ -26,8 +26,9 @@ export const receivedOpenAPISchema = createAsyncThunk(
'nodes/receivedOpenAPISchema', 'nodes/receivedOpenAPISchema',
async (_, { rejectWithValue }) => { async (_, { rejectWithValue }) => {
try { try {
const url = [window.location.origin, 'openapi.json'].join('/'); const response = await fetch(
const response = await fetch(url); `${window.location.href.replace(/\/$/, '')}/openapi.json`
);
const openAPISchema = await response.json(); const openAPISchema = await response.json();
const schemaJSON = JSON.parse( const schemaJSON = JSON.parse(