From aa1484c285022dab873a8f77061b3b68d44cfcfd Mon Sep 17 00:00:00 2001 From: LincPay Date: Sat, 15 Aug 2026 16:46:33 +0530 Subject: [PATCH] build(dev): proxy /api in dev and preview so the production bundle is testable --- vite.config.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index e249220..6acb229 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,10 +3,34 @@ import react from '@vitejs/plugin-react' import tailwindcss from '@tailwindcss/vite' // https://vite.dev/config/ +/** + * The backend, for the two dev-time servers. Production does not use either of + * these — nginx or httpd proxies /api/ there — but `npm run preview` serves the + * real production bundle, which is built with a *relative* API base and so has + * no host to call without a proxy in front of it. Without this block the only + * way to exercise the shipped artifact is to deploy it, which is how a bundle + * reaches a demo server untested. + */ +const API_TARGET = 'http://127.0.0.1:8082' + +const proxy = { + '/api': { + target: API_TARGET, + changeOrigin: true, + }, +} + export default defineConfig({ plugins: [react(), tailwindcss()], server: { // 5180 belongs to BharatLinc-UI — UdyamLinc runs alongside it port: 5182, + proxy, + }, + // Serves dist/ exactly as it will be served in production, with the same + // relative API base, so a preview run is a real rehearsal of the deployment. + preview: { + port: 4173, + proxy, }, })