From f25b24f87b5f14f6094fa9b7bc30e70d794f39a6 Mon Sep 17 00:00:00 2001 From: Hitesh Kumar Date: Sun, 19 Jul 2026 12:13:23 +0530 Subject: [PATCH 1/2] fix: add vercel.json to handle client-side routing on Vercel Without this, any direct navigation to a deep route (e.g. /activity, /authors, /app/settings) returns a 404 because Vercel serves the static dist/ output and has no file at those paths. The rewrite rule sends all non-API paths to index.html so React Router can handle routing on the client side. --- vercel.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 vercel.json diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..329e7a8 --- /dev/null +++ b/vercel.json @@ -0,0 +1,12 @@ +{ + "rewrites": [ + { + "source": "/api/:path*", + "destination": "/api/:path*" + }, + { + "source": "/(.*)", + "destination": "/index.html" + } + ] +} From 8cfde3a2520f462ba035b3bafc92a8f7d605cbc1 Mon Sep 17 00:00:00 2001 From: Hitesh Kumar Date: Sun, 19 Jul 2026 12:16:35 +0530 Subject: [PATCH 2/2] fix: wire frontend to Railway API backend in production src/api/client.ts - API base is now VITE_API_URL + '/api' when the env var is set, falling back to '/api' (Vite dev proxy) when it is not. This means local dev is unchanged; Vercel builds point straight at the Railway backend. server/index.ts - Add gitstats.hivarsoft.com and *.vercel.app to the CORS allowlist so the deployed frontend can reach the Railway API. vercel.json - Remove the broken /api rewrite that pointed back at Vercel itself. - Keep only the SPA catch-all so React Router handles all deep links. .env.example - Document VITE_API_URL for anyone setting up the project. --- server/index.ts | 11 ++++++++++- src/api/client.ts | 4 +++- vercel.json | 4 ---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/index.ts b/server/index.ts index cd10641..2011e3e 100644 --- a/server/index.ts +++ b/server/index.ts @@ -13,7 +13,16 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)) const app = express() const PORT = parseInt(process.env.PORT ?? '3001') -app.use(cors({ origin: ['http://localhost:5173', 'http://localhost:4173', 'http://localhost:3000'] })) +app.use(cors({ + origin: [ + 'http://localhost:5173', + 'http://localhost:4173', + 'http://localhost:3000', + 'https://gitstats.hivarsoft.com', + // also allow any *.vercel.app preview deployments + /\.vercel\.app$/, + ], +})) app.use(express.json({ limit: '1mb' })) // ─── Health check ───────────────────────────────────────────────────────────── diff --git a/src/api/client.ts b/src/api/client.ts index c884b60..970f757 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -1,6 +1,8 @@ import type { GitStatsReport } from '@/types' -const BASE = '/api' +// In dev, Vite proxies /api → localhost:3001. +// In production (Vercel), VITE_API_URL is set to the Railway backend URL. +const BASE = (import.meta.env.VITE_API_URL ?? '').replace(/\/$/, '') + '/api' export interface AnalyzeResponse { report: GitStatsReport diff --git a/vercel.json b/vercel.json index 329e7a8..1323cda 100644 --- a/vercel.json +++ b/vercel.json @@ -1,9 +1,5 @@ { "rewrites": [ - { - "source": "/api/:path*", - "destination": "/api/:path*" - }, { "source": "/(.*)", "destination": "/index.html"