Set Up Application Proxies
The Node, Nest and Express application generators have an option to configure other projects in the workspace to proxy API requests. This can be done by passing the --frontendProject
with the project name you wish to enable proxy support for.
❯
nx g @nx/node:app <node-app> --frontendProject my-react-app
❯
nx g @nx/nest:app <nest-app> --frontendProject my-react-app
❯
nx g @nx/express:app <express-app> --frontendProject my-react-app
This command will generate and configure a proxy.conf.json
file that will be used by the frontend project's serve
target to redirect calls to /api
to instead go to http://localhost:3000/api
.
1{
2 "/api": {
3 "target": "http://localhost:3000",
4 "secure": false
5 }
6}
7
For more information on the proxy config file format, see the Webpack or Vite docs.