diff --git a/web/client/orval.config.ts b/web/client/orval.config.ts index 282e99bb9c..2adc509a70 100644 --- a/web/client/orval.config.ts +++ b/web/client/orval.config.ts @@ -12,6 +12,8 @@ export default defineConfig({ name: 'fetchAPI', }, }, + baseUrl: '/proxy/8000' }, }, }) + diff --git a/web/client/src/api/instance.ts b/web/client/src/api/instance.ts index 329afbbfb9..513e2817f9 100644 --- a/web/client/src/api/instance.ts +++ b/web/client/src/api/instance.ts @@ -42,20 +42,7 @@ export async function fetchAPI( config const hasSearchParams = Object.keys({ ...params }).length > 0 const fullUrl = url.replace(/([^:]\/)\/+/g, '$1') - - let input = new URL( - `${getUrlPrefix()}${fullUrl}`.replaceAll('//', '/'), - window.location.origin, - ) - if(url.includes('api/')) { - const otherUrl = "/proxy/8000/" - input = new URL( - `${otherUrl}${fullUrl}`.replaceAll('//', '/'), - window.location.origin, - ) - } - - + const input = new URL(getUrlWithPrefix(fullUrl), window.location.origin) if (hasSearchParams) { const searchParams: Record = Object.entries({ @@ -136,9 +123,21 @@ function toRequestBody(obj: unknown): BodyInit { } } -export function getUrlPrefix(): string { - return '/proxy/8000/' - //return isStringEmptyOrNil(window.__BASE_URL__) ? '/' : window.__BASE_URL__ +export function getUrlWithPrefix(url: string = '/'): string { + let urlWithPrefix = `${ + isStringEmptyOrNil(window.__BASE_URL__) ? '/' : window.__BASE_URL__ + }/${url}` + + if(!urlWithPrefix.includes('proxy/8000')){ + urlWithPrefix = `${'/proxy/8000/'}/${url}` + } + + while (urlWithPrefix.includes('//')) { + urlWithPrefix = urlWithPrefix.replaceAll('//', '/') + } + + return urlWithPrefix } export default fetchAPI + diff --git a/web/client/vite.config.ts b/web/client/vite.config.ts index df3c55b558..500e96e37b 100644 --- a/web/client/vite.config.ts +++ b/web/client/vite.config.ts @@ -1,11 +1,11 @@ import path from 'path' import { defineConfig } from 'vitest/config' import react from '@vitejs/plugin-react-swc' +import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js' + +const BASE_URL = '/proxy/8000/' +const BASE = BASE_URL == null || BASE_URL === '' ? '/' : BASE_URL -const BASE_URL = process.env.BASE_URL ?? '' -//const BASE = BASE_URL == null || BASE_URL === '' ? '/' : BASE_URL -const BASE = '/proxy/8000/' -const APP_BASE = '/proxy/8001/' // https://vitejs.dev/config/ export default defineConfig({ base: BASE, @@ -29,12 +29,13 @@ export default defineConfig({ }, build: { outDir: 'dist', + modulePreload: false, }, define: { __BASE_URL__: JSON.stringify(BASE_URL), __IS_HEADLESS__: JSON.stringify(Boolean(process.env.IS_HEADLESS ?? false)), }, - plugins: [react()], + plugins: [react(), cssInjectedByJsPlugin()], test: { globals: true, environment: 'jsdom', @@ -43,29 +44,29 @@ export default defineConfig({ }, server: process.env.NODE_ENV === 'testing' - ? {} - : - { - proxy: { - [`${BASE_URL}/api`]: { - target: 'http://api:8000', - rewrite: path => BASE, - }, - [`${BASE_URL}/data-catalog`]: { - target: 'http://app:8001', - rewrite: path => BASE, - }, - [`${BASE_URL}/data`]: { - target: 'http://app:8001', - rewrite: path => BASE, - }, - [`${BASE_URL}/lineage`]: { - target: 'http://app:8001', - rewrite: path => BASE, - }, + ? {} + : { + proxy: { + [`${BASE_URL}/api`]: { + target: 'http://api:8000', + rewrite: path => path.replace(`${BASE_URL}/api`, '/api'), + }, + [`${BASE_URL}/data-catalog`]: { + target: 'http://app:8001', + rewrite: path => BASE, + }, + [`${BASE_URL}/data`]: { + target: 'http://app:8001', + rewrite: path => BASE, + }, + [`${BASE_URL}/lineage`]: { + target: 'http://app:8001', + rewrite: path => BASE, }, }, + }, preview: { port: 8005, }, }) +