Fix pay slips 404 when frontend hits legacy API on port 8001.
Default API URL to 8002, align dev proxy, and detect outdated health before listing payslips. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9f246ee31c
commit
19a28bb4c2
20
backend/scripts/check-payslips-api.ps1
Normal file
20
backend/scripts/check-payslips-api.ps1
Normal file
@ -0,0 +1,20 @@
|
||||
# Quick check: Claim API on 8002 should expose /api/payslips (401), not 404.
|
||||
$ports = @(8002, 8001)
|
||||
foreach ($port in $ports) {
|
||||
$base = "http://127.0.0.1:$port"
|
||||
try {
|
||||
$health = Invoke-RestMethod -Uri "$base/api/health" -TimeoutSec 3
|
||||
$payslip = Invoke-WebRequest -Uri "$base/api/payslips" -TimeoutSec 3 -SkipHttpErrorCheck
|
||||
$ok = $health.features.payslips -eq $true
|
||||
$code = $payslip.StatusCode
|
||||
Write-Host "Port $port : health=$($health.status) payslips=$code payslips_feature=$ok"
|
||||
if ($port -eq 8002 -and -not $ok) {
|
||||
Write-Host " -> Restart backend from this repo (backend\start-local.bat)"
|
||||
}
|
||||
if ($port -eq 8001 -and $code -eq 404) {
|
||||
Write-Host " -> Old API on 8001; stop it if frontend should use 8002"
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Port $port : not reachable"
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,7 @@ async def health_check():
|
||||
"mongodb": "connected" if mongo_healthy else "disconnected",
|
||||
"database": db.name,
|
||||
"version": "2.0.0",
|
||||
"features": {"payslips": True},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ webpackConfig.devServer = (devServerConfig) => {
|
||||
devServerConfig.proxy = [
|
||||
{
|
||||
context: ["/api", "/uploads"],
|
||||
target: "http://127.0.0.1:8000",
|
||||
target: process.env.REACT_APP_BACKEND_URL || "http://127.0.0.1:8002",
|
||||
changeOrigin: true,
|
||||
// Excel COM PDF conversion can take longer than the default proxy timeout
|
||||
proxyTimeout: 180000,
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
CircleNotch,
|
||||
X,
|
||||
} from "@phosphor-icons/react";
|
||||
import { api, apiErrorText } from "../lib/api";
|
||||
import { api, apiBaseUrl, apiErrorText } from "../lib/api";
|
||||
|
||||
function formatPayslipDate(iso) {
|
||||
if (!iso) return "—";
|
||||
@ -46,6 +46,16 @@ export default function PaySlips() {
|
||||
setLoading(true);
|
||||
setErr("");
|
||||
try {
|
||||
const health = await api.get("/health");
|
||||
if (!health.data?.features?.payslips) {
|
||||
setErr(
|
||||
`Connected API at ${apiBaseUrl} does not include pay slips (likely port 8001 legacy). ` +
|
||||
"Use http://127.0.0.1:8002 — run backend\\start-local.bat and set REACT_APP_BACKEND_URL in frontend/.env, then restart yarn."
|
||||
);
|
||||
setItems([]);
|
||||
setSelected(null);
|
||||
return;
|
||||
}
|
||||
const r = await api.get("/payslips");
|
||||
const list = r.data.items || [];
|
||||
setItems(list);
|
||||
@ -56,9 +66,11 @@ export default function PaySlips() {
|
||||
} catch (e) {
|
||||
const status = e?.response?.status;
|
||||
if (status === 404) {
|
||||
setErr(
|
||||
"Pay slips API is not available. Restart the backend (port 8002) or redeploy the API on Render after pulling the latest code."
|
||||
);
|
||||
const hint =
|
||||
apiBaseUrl.includes(":8001")
|
||||
? "Your frontend is pointing at port 8001 (old API). Set REACT_APP_BACKEND_URL=http://127.0.0.1:8002 in frontend/.env and restart yarn."
|
||||
: "Start the Claim API with backend\\start-local.bat (port 8002). If port 8001 is still running, stop that old process.";
|
||||
setErr(`Pay slips API not found at ${apiBaseUrl}/api/payslips. ${hint}`);
|
||||
} else {
|
||||
setErr(apiErrorText(e));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user