So, here's the situation: I have an app that is 4.6MB when running on ng serve.
When I run:
ng serve --prod
The file size drops to 1MB.
However, when I use --prod, my entire application breaks.
All of my services (which are promise-based) that send requests to the server stop working.
The strange thing is that just using ng serve works fine and certain parts of ng serve --prod work as well, as long as there are no server requests involved.
I'm not including any code since the version with ng serve functions correctly.
The question remains:
Why am I experiencing this behavior?
Furthermore, at times, the app using ng serve --prod suddenly starts working perfectly out of nowhere, only to break again after restarting the app.
EDIT: more DETAILS:
I've used Fiddler to verify all the details:
https://i.sstatic.net/Zsqe8.png
As you can see, everything checks out.
Now, here's the code responsible for simulating the request on the client side:
login(uName: string, pw: string, type: number): Promise<any> {
return new Promise(resolve => {
if (type === 1) {
const options = new RequestOptions({ headers: this.headers });
const body = JSON.stringify({ username: uName, password: pw });
this.http.post(this.loginUrl, body, options)
.toPromise()
.then(response => {
resolve(response);
})
.catch(this.handleError);
} else if (type === 2 || type === 3) {
this.http.post(this.loginUrl, { username: uName, token: pw })
.toPromise()
.then(response => {
resolve(response);
})
.catch(this.handleError);
}
});
}
Everything works flawlessly when I use ng serve alone (Network Tab):
https://i.sstatic.net/SMvaP.png
As shown, I'm logged in and receiving a response.
However,
As soon as I run
ng serve --prod
The same login request with the same details stops functioning:
https://i.sstatic.net/3z9Cc.jpg
This is extremely puzzling.
All of my methods handling server requests remain unchanged.
I receive a "Bad Request" error with some error code from the server itself (like "email not filled", which is also odd considering I am sending the correct parameters)