Skip to content

Commit

Permalink
feat(gui): proxy Admin API via gui's port
Browse files Browse the repository at this point in the history
  • Loading branch information
raoxiaoyan committed Sep 29, 2024
1 parent b166324 commit 372af35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ export const config = {
},

get ADMIN_API_URL() {
const ADMIN_API_URL = getConfig<string | null>('ADMIN_API_URL', null)
const ADMIN_API_URL = getConfig('ADMIN_API_URL', '')

if (ADMIN_API_URL) {
return /^(https?:)?\/\//.test(ADMIN_API_URL)
? ADMIN_API_URL
: `${window.location.protocol}//${ADMIN_API_URL}`
return /^(https?:)?\/\//.test(ADMIN_API_URL) ? ADMIN_API_URL : `${window.location.protocol}//${ADMIN_API_URL}`
}

const port = window.location.protocol.toLowerCase() === 'https:'
? config.ADMIN_API_SSL_PORT
: config.ADMIN_API_PORT
const baseUrl = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`

return `${window.location.protocol}//${window.location.hostname}:${port}`
return `${baseUrl}${config.ADMIN_GUI_PATH === '/' ? '' : config.ADMIN_GUI_PATH}/gateway/api`
},

get ANONYMOUS_REPORTS() {
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export default defineConfig({
server: {
proxy: {
'/kconfig.js': process.env.KONG_GUI_URL || 'http://127.0.0.1:8002',
'/gateway/api': {
target: process.env.KONG_GUI_API_URL || 'http://localhost:8001',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/gateway\/api/, ''),
},
},
port: 8080,
},
Expand Down

0 comments on commit 372af35

Please sign in to comment.