How do you set up a Vite proxy for development?

MERN: connecting React and the API · Freshers and experienced

Model answer

In vite.config.js add server: { proxy: { '/api': 'http://localhost:3000' } }. The browser calls the Vite origin, and Vite forwards /api requests to Express, so no CORS setup is needed in development. It only works in the dev server, not in production builds.

Learn this topic

useEffect and Fetching Data from Your API: Loading, Errors and Cleanup in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions