fix: correct double /api/ prefix in report download URL

The download function used `/api/reports/download/{id}` as the URL for
the axios instance which already has `baseURL: '/api'`. This resulted in
requests to `/api/api/reports/download/{id}`, causing nginx to serve
the SPA index.html (status 200, text/html) instead of proxying to the
backend. The HTML was then saved as .xlsx, making Excel unable to open it.

Fix: Use `/reports/download/{id}` for axios (which prepends baseURL)
and keep the full `/api/reports/download/{id}` for the window.open fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
CCS Admin 2026-02-26 23:10:12 +00:00
parent dbb5afaeb9
commit 4cd52dd0b2

View file

@ -54,8 +54,7 @@ export function ReportsPage() {
const downloadReport = (reportId: number) => {
const token = localStorage.getItem('access_token')
const url = `/api/reports/download/${reportId}`
api.get(url, { responseType: 'blob' })
api.get(`/reports/download/${reportId}`, { responseType: 'blob' })
.then((res) => {
const blob = new Blob([res.data as BlobPart], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@ -77,7 +76,7 @@ export function ReportsPage() {
})
.catch(() => {
if (token) {
window.open(`${url}?token=${encodeURIComponent(token)}`, '_blank')
window.open(`/api/reports/download/${reportId}?token=${encodeURIComponent(token)}`, '_blank')
}
})
}