|Possibilities||Support different host||Support same host||Description|
|Environment variables only||Yes||Yes||cors must be relaxed on the backend|
|Proxy||No||Yes||Emulate as if the backend and frontend requests are served from the same host (hostname+port)|
You can use environment variables to inject the right configuration at build time.
const apiBaseUrl = process.env.NODE_ENV === 'development' ? 'localhost:3001' : '/'
- Your building engine also allows injecting environment variables, check their documentation
Example of production deployment
/ - static server returns index.html with the frontend framework (React, Next, ...) /todos - static server returns index.html with the frontend framework (React, Next, ...) /api/todos - server handles any /api/* requests using the backend implementation
All building engine allows the configuration of a proxy with their development server, check their documentation. Example:
In production, see Proxy implementation