LocalHost, Angular 11 (https://localhost:4200) and Node API (https://localhost:3001), both are using OpenSSL, browser is Chrome. To iron out Status: CORS error (due to diff ports) I follow this adding Proxy, got this in Angular's console
[HPM] Error occurred while trying to proxy request /somewhere1 from localhost:4200 to https://localhost:3001 (DEPTH_ZERO_SELF_SIGNED_CERT) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Following didn't help:
- Confirmed the Chrome brought up by F5 has
chrome://flags/#allow-insecure-localhostEnabled. - Added
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";to Node API's server.js.
Proxy.conf.json
{
"context":
[
"/somewhere1",
"/xyz/somewhere"
],
"target" : "https://localhost:3001",
"secure": true,
"changeOrigin": true,
"rejectUnauthorzied": false,
"logLevel": "info"
}
angular.json
"serve": {
...
"options": {
"browserTarget": "myapp:build",
"ssl": true,
"proxyConfig": "src/proxy.conf.json"
Call API:
private http: HttpClient;
const httpOptions =
{
headers: new HttpHeaders({'Content-Type': 'application/json'}),
rejectUnauthorized: false
};
this.http.post<any[]>("/somewhere1/hello", {}, httpOptions).subscribe
Believe this is Angular end.
