@yossiz אמר בלא מצליח לשלוח headers באנגולר:
התיעוד ש-@dovid הביא
- Add the following content to the new proxy file:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
- In the CLI configuration file, angular.json, add the proxyConfig option to the serve target:
...
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-application-name:build",
"proxyConfig": "src/proxy.conf.json"
},
...
Rewrite the URL path
- The pathRewrite proxy configuration option lets you rewrite the URL path at run time. For example, you can specify the following pathRewrite value to the proxy configuration to remove "api" from the end of a path.
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"pathRewrite": {
"^/api": ""
}
}
}
- If you need to access a backend that is not on localhost, set the changeOrigin option as well. For example:
{
"/api": {
"target": "http://npmjs.org",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true
}
}
מה שאני כתבתי:
- קובץ: "proxy.conf.json" הנמצא ב src
{
"/api": {
"target": "http://localhost:3000/",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/api": ""
}
}
}
- קובץ: "angular.json" שנמצא מחוץ ל src
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "love-volunteers:build",
"proxyConfig": "src/proxy.conf.json"
},
וכשאני מפעיל npm start
זה מפעיל גם את הפרוקסי.
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config src/proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
פספסתי משהו?