I have a pretty simple Angular 6 service that calls a Spring Boot service. Here is how it looks like in Angular :
getData(user, numberOfRequests, graphDepth, max): Observable<String> {
var headers = new Headers();
var body = { "user" : user,
"numberofRequests" : numberOfRequests,
"graphDepth" : graphDepth,
"max" : max };
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post<String>('http://XX.XX.XXX.XXX:8083/collect', body, httpOptions);
}
Here is the server side :
@CrossOrigin(origins = "*")
@RequestMapping(value = "/collect", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
@ResponseBody
public String startServices(@RequestBody UserParameters parameters) {
LOGGER.info("Calling for data");
String jsonOutput = collect.getData(parameters);
LOGGER.info("Data ready to be served");
return jsonOutput;
}
It works well when both application run locally or when they run on 2 different VMs. But when I deploy on a cloud service I get something that seems to be a CORS error :
Reason: CORS request did not succeed
error: error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, … }
headers: Object { normalizedNames: Map(0), lazyUpdate: null, headers: Map(0) }
message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: null
This error happens when the webapp and the backend run on the same VM or in two separate VM with 2 different IP...
Do you know what could cause that problem ? How can it be a CORS error ? And do you know how can I try to fix it ?
Thanks!