This is my service
export class user {
apiUrl = 'http://localhost:8080/api/v1/'
constructor(private _http: HttpClient) {}
getUser() {
return this._http.get(this.apiUrl + `user`, {});
}
how to add a header for CORS
control ?
This is my service
export class user {
apiUrl = 'http://localhost:8080/api/v1/'
constructor(private _http: HttpClient) {}
getUser() {
return this._http.get(this.apiUrl + `user`, {});
}
how to add a header for CORS
control ?
I know its too late but for others, the only way to to disable/enable CORS in Angular is use proxy configure as your angular option.
for example you can put proxy.json
into assets
folder and fill it as below contents:
assets/proxy.json
:
{
"/api/v1/*": {
"target": "http://localhost:8080",
"secure": false,
}
}
and change your serve/build
with below code in angular.json
file :
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-project-name:build",
"proxyConfig": "assets/proxy.json"
},
}
}
NOTE: don't forget to enable CORS header in your server side project.