Skip to content

Commit dae2879

Browse files
committed
proxy fix
1 parent 4e194f8 commit dae2879

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

index-build.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4-
<base href="/__BASE_PATH__/" />
4+
<base href="/__BASE_PATH__" />
55
<script>
6-
window.dynamicBasePath = '/__BASE_PATH__/' // Vue router links
6+
// Vue router & API links:
7+
window.dynamicBasePath = '/__BASE_PATH__'
78
</script>
89
<meta charset="UTF-8" />
9-
<link rel="icon" href="favicon.svg" />
10+
<link rel="icon" href="/__BASE_PATH__/favicon.svg" />
1011
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
11-
<script src="rdkit/RDKit_minimal.js"></script>
12+
<script src="/__BASE_PATH__/rdkit/RDKit_minimal.js"></script>
1213
<title>OMGUI</title>
1314
</head>
1415
<body>

src/api/BaseApi.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,9 @@ import { useMainStore } from '@/stores/MainStore'
1616
// - - -
1717
// Every CLI or Jupyter Notebook runs on a different port, starting at 8024 and up.
1818
const DEFAULT_PORT: number = 8024
19-
const regEx = new RegExp(/^(.*)\/proxy\/(\d{4})/)
20-
const proxyPrefix: string = (window.location.pathname ?? '').match(regEx)?.[1] ?? ''
21-
const proxyPort: number | null = Number((window.location.pathname ?? '').match(regEx)?.[2]) ?? null
19+
const BASE_PATH = (window as any).dynamicBasePath
2220
const API_URL = (port: number = DEFAULT_PORT): string => {
23-
return process.env.NODE_ENV == 'development'
24-
? // When we're running the development server,
25-
// we try connecting to the API on port 8024 or up.
26-
`http://127.0.0.1:${port}/api/v1/`
27-
: proxyPort
28-
? // When we're running the server on a proxy URL, we get the
29-
// port from the URL's path and include it into our API calls.
30-
// See vite.config.ts for more info about the proxy URL.
31-
`${proxyPrefix}/proxy/${proxyPort}/api/v1/`
32-
: // For regular use, the API is just a relative path.
33-
'/api/v1/'
21+
return process.env.NODE_ENV == 'development' ? `http://127.0.0.1:${port}/api/v1/` : `${BASE_PATH}/api/v1/`
3422
}
3523

3624
// Type declarations

src/stores/ConfigStore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,35 @@ import { apiFetch, mainApi } from '@/api'
1010
// Type declarations
1111
type State = {
1212
_config: Record<string, any>
13+
_ready: boolean
1314
}
1415

1516
export const useConfigStore = defineStore('configStore', {
1617
state: (): State => ({
1718
_config: {},
19+
_ready: false,
1820
}),
1921
getters: {
2022
config: (state) => state._config,
2123
stateless: (state) => state._config.stateless || false,
2224
appName: (state) => state._config.app_name || 'omgui',
2325
workspace: (state) => state._config.workspace || 'DEFAULT',
2426
session: (state) => state._config.session || null,
27+
basePath: (state) => state._config.base_path,
2528
},
2629
actions: {
2730
// Load config from the API
2831
async load() {
32+
if (this._ready) return
2933
apiFetch(mainApi.getConfig(), {
3034
onSuccess: (data) => {
3135
this._config = data
36+
this._ready = true
37+
if (data.base_path) {
38+
// Update API base path if needed.
39+
// mainApi.apiClient.defaults.baseURL = data.base_path
40+
console.log(3333, data.base_path)
41+
}
3242
},
3343
onError: (err) => {
3444
console.error('Failed to load config:', err)

vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export default defineConfig(({ command }) => {
4848
// outDir: 'dist',
4949
rollupOptions: {
5050
input: {
51-
main: 'index-build.html',
52-
},
51+
main: 'index-build.html',
52+
},
5353
},
5454
},
5555
}
5656
}
5757

5858
return commonConfig
59-
})
59+
})

0 commit comments

Comments
 (0)