build(dev): proxy /api in dev and preview so the production bundle is testable
This commit is contained in:
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user