I have a NodeJs API on an Ubuntu server. I can call it via browser or postman without problem. But when i call it with ionic, i get “net::ERR_EMPTY_RESPONSE” in Chrome, “Cross-Origin Request Blocked” in Firefox.
In NodeJs app, CORS is enabled for all. (app.use(cors());
)
Already, as i said, i can call it with browser or postman with success. Only ionic (angular) app got errors. So i guess it’s about ionic/angular.
This is really weird problem. Any idea?
I’ve seen that error in Firefox when the URL is not correct, it can be misleading.
It’s correct. I’m sure. I searched more and found a few discussions. All says it’s about CORS. I get error with Post request that i use for authentication. As i understood, it’s Angular specific:
Firefox Says:
The HTTP request which makes use of CORS failed because the HTTP connection failed at either the network or protocol level. The error is not directly related to CORS, but is a fundamental network error of some kind.
When i changed request to form-urlencoded from json, post method (auth) worked:
login(username: string, password: string) {
const body = `username=${username}&password=${password}`;
const headers = new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'});
return this.http.post<any>(this.apiUrl + '/user/authenticate', body, { headers: headers }).pipe(
...
But now, i get same error for GET methods. This is really weird problem that took my 2 days. 
I have this little project. Perhaps it helps you to solve your problem. But it has no auth🤔
Well. I found problem in 3. day. It was load balancer. When app reachs server without load balancer device, no problem.
Btw, i was using authentication header. So my requests were preflight. App first sends Option method. Load balancer block preflight requests. So any settings about preflight on express application didn’t work. Requests didn’t reach express. I tried really everyting. At last i thought about hardware. 