Angular Nx Tutorial - Step 6: Proxy
Nx.dev Tutorial | Angular | Step 6: Configure Proxy
You passed --frontendProject=todos
when creating the node application. What did that argument do?
It created a proxy configuration that allows the Angular application to talk to the API in development.
To see how it works, open angular.json
and find the serve
target of the todos app.
1{
2 "serve": {
3 "builder": "@angular-devkit/build-angular:dev-server",
4 "options": {
5 "browserTarget": "todos:build",
6 "proxyConfig": "apps/todos/proxy.conf.json"
7 },
8 "configurations": {
9 "production": {
10 "browserTarget": "todos:build:production"
11 }
12 }
13 }
14}
Note the proxyConfig
property.
Now open proxy.conf.json
:
1{
2 "/api": {
3 "target": "http://localhost:3333",
4 "secure": false
5 }
6}
This configuration tells nx serve
to forward all requests starting with /api
to the process listening on port 3333.
!!!!! Now run both "npx nx serve todos" and "npx nx serve api" in separate terminals, open http://localhost:4200. What do you see !!!!! Todos application is working! 404 in the console Todos are displayed but the Add Todo button doesn't work