Skip to content

Commit a6f9ca9

Browse files
fix(ui): adapt dashboard deployment paths
1 parent 926f080 commit a6f9ca9

7 files changed

Lines changed: 120 additions & 101 deletions

File tree

Lines changed: 87 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="apple-touch-icon" href="favicon.svg" />
88
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
99
<title>Juspay Decision Engine Dashboard</title>
10-
<script type="module" crossorigin src="/dashboard/assets/index-DJWwZ-wJ.js"></script>
11-
<link rel="stylesheet" crossorigin href="/dashboard/assets/index-B3hSXaF9.css">
10+
<script type="module" crossorigin src="/decision-engine/assets/index-CVLcvas3.js"></script>
11+
<link rel="stylesheet" crossorigin href="/decision-engine/assets/index-B3hSXaF9.css">
1212
</head>
1313
<body>
1414
<div id="root"></div>

website/src/components/pages/OverviewPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'lucide-react'
1717
import { useMerchantStore } from '../../store/merchantStore'
1818
import { useAuthStore } from '../../store/authStore'
19-
import { apiPost, fetcher } from '../../lib/api'
19+
import { apiFetch, apiPost, fetcher } from '../../lib/api'
2020
import {
2121
AnalyticsRange,
2222
AnalyticsOverviewResponse,
@@ -46,8 +46,8 @@ function useHealth() {
4646
const [status, setStatus] = useState<'up' | 'down' | 'loading'>('loading')
4747

4848
useEffect(() => {
49-
fetch('/health')
50-
.then((response) => setStatus(response.ok ? 'up' : 'down'))
49+
apiFetch<{ message: string }>('/health')
50+
.then(() => setStatus('up'))
5151
.catch(() => setStatus('down'))
5252
}, [])
5353

website/src/lib/api.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import { tokenRef } from './tokenRef'
33

44
const DEBUG_API = true
55
const DEFAULT_TENANT_ID = import.meta.env.VITE_DEFAULT_TENANT_ID ?? 'public'
6+
const API_BASE_PATH = (import.meta.env.VITE_API_BASE_PATH ?? '/decision-engine-api').replace(/\/$/, '')
7+
const FEATURE_HEADER = import.meta.env.VITE_FEATURE_HEADER ?? 'decision-engine'
8+
9+
function resolveApiPath(path: string) {
10+
if (/^https?:\/\//.test(path)) return path
11+
const normalizedPath = path.startsWith('/') ? path : `/${path}`
12+
if (normalizedPath.startsWith(`${API_BASE_PATH}/`) || normalizedPath === API_BASE_PATH) {
13+
return normalizedPath
14+
}
15+
return `${API_BASE_PATH}${normalizedPath}`
16+
}
617

718
function logRequest(method: string, path: string, body?: unknown) {
819
if (!DEBUG_API) return
@@ -46,19 +57,21 @@ export async function apiFetch<T>(
4657
): Promise<T> {
4758
const method = options?.method || 'GET'
4859
const body = options?.body ? JSON.parse(options.body as string) : undefined
60+
const requestPath = resolveApiPath(path)
4961

50-
logRequest(method, path, body)
62+
logRequest(method, requestPath, body)
5163

5264
try {
5365
const token = tokenRef.get()
5466
const headers = new Headers(options?.headers)
5567
headers.set('Content-Type', 'application/json')
5668
headers.set('x-tenant-id', DEFAULT_TENANT_ID)
69+
headers.set('x-feature', FEATURE_HEADER)
5770
if (token) {
5871
headers.set('Authorization', `Bearer ${token}`)
5972
}
6073

61-
const res = await fetch(path, {
74+
const res = await fetch(requestPath, {
6275
...options,
6376
headers,
6477
})
@@ -73,7 +86,7 @@ export async function apiFetch<T>(
7386
responseBody = responseText
7487
}
7588

76-
logResponse(path, res.status, res.statusText, responseBody)
89+
logResponse(requestPath, res.status, res.statusText, responseBody)
7790

7891
// Only clear session when the JWT itself is confirmed invalid/expired.
7992
// A generic 401 (e.g. missing API key on a protected route) must NOT wipe the session.
@@ -94,14 +107,14 @@ export async function apiFetch<T>(
94107
import('../store/authStore').then(({ useAuthStore }) => {
95108
useAuthStore.getState().clearAuth()
96109
})
97-
window.location.href = '/dashboard/login'
110+
window.location.href = `${import.meta.env.BASE_URL}login`
98111
throw new Error('Session expired')
99112
}
100113
}
101114

102115
if (!res.ok) {
103116
const error = new Error(`API error ${res.status}: ${responseText}`)
104-
logError(path, error)
117+
logError(requestPath, error)
105118
throw error
106119
}
107120

@@ -111,7 +124,7 @@ export async function apiFetch<T>(
111124

112125
return JSON.parse(responseText) as T
113126
} catch (error) {
114-
logError(path, error)
127+
logError(requestPath, error)
115128
throw error
116129
}
117130
}

website/src/pages/OnboardingPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function OnboardingPage() {
1616
const navigate = useNavigate()
1717
const { updateMerchant } = useAuthStore()
1818
const { setMerchantId } = useMerchantStore()
19+
const assetBaseUrl = import.meta.env.BASE_URL
1920

2021
const [merchantName, setMerchantName] = useState('')
2122
const [loading, setLoading] = useState(false)
@@ -58,7 +59,7 @@ export function OnboardingPage() {
5859
className="min-h-screen flex flex-col items-center justify-center p-4"
5960
style={{
6061
backgroundColor: '#212e46',
61-
backgroundImage: 'url(/dashboard/images/auth_bg.svg)',
62+
backgroundImage: `url(${assetBaseUrl}images/auth_bg.svg)`,
6263
backgroundSize: 'cover',
6364
backgroundPosition: 'center',
6465
backgroundAttachment: 'fixed',

website/src/vite-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
interface ImportMetaEnv {
44
readonly VITE_DEFAULT_TENANT_ID?: string
5+
readonly VITE_API_BASE_PATH?: string
6+
readonly VITE_FEATURE_HEADER?: string
57
}
68

79
interface ImportMeta {

website/vite.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import react from '@vitejs/plugin-react'
33

44
export default defineConfig(({ command }) => {
55
const isDevServer = command === 'serve'
6-
const publicBaseUrl = isDevServer ? '/' : '/dashboard/'
6+
const publicBaseUrl = isDevServer ? '/' : '/decision-engine/'
77
const backendTarget = 'http://localhost:8080'
8+
const apiProxyPrefix = '/decision-engine-api'
89

9-
const createApiProxy = () => ({
10+
const createApiProxy = (rewritePrefix?: string) => ({
1011
target: backendTarget,
1112
changeOrigin: true,
13+
rewrite: rewritePrefix ? (path) => path.replace(new RegExp(`^${rewritePrefix}`), '') : undefined,
1214
configure: (proxy) => {
1315
proxy.on('proxyReq', (_proxyReq, req) => {
1416
console.log(`\n[PROXY] ${new Date().toISOString()}`)
@@ -31,6 +33,7 @@ export default defineConfig(({ command }) => {
3133
base: publicBaseUrl,
3234
server: {
3335
proxy: {
36+
'^/decision-engine-api(?:/.*)?$': createApiProxy(apiProxyPrefix),
3437
'/decide-gateway': createApiProxy(),
3538
'/decision_gateway': createApiProxy(),
3639
'/merchant-account': createApiProxy(),

0 commit comments

Comments
 (0)