Creating a proxy.conf.json
in Angular’s src
directory will allow you to proxy requests.
You might have a Node.js server running on Port 3000 and your Angular development server on Port 4200. For forwarding all requests made in the Angular app to “/api/<>” to the actual Node.js server, running on a different port, use the following:
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"logLevel": "debug"
}
}
Import this configuration in your angular.json
:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"proxyConfig": "src/proxy.conf.json"
}