Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/client/orval.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default defineConfig({
name: 'fetchAPI',
},
},
baseUrl: '/proxy/8000'
},
},
})

33 changes: 16 additions & 17 deletions web/client/src/api/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,7 @@ export async function fetchAPI<T = any, B extends object = any>(
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<string, string> = Object.entries({
Expand Down Expand Up @@ -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

51 changes: 26 additions & 25 deletions web/client/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
Expand All @@ -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,
},
})