So, my app is being served by a simple web server, under "https://localhost:8443/app", while the same web server returns json responses under eg. "https://localhost:8443/api/login".
TLS is set up with a self signed certificate for now.
when I request the app, I get the certificate warning, which I skip, and then I see my login page.
on clicking the login button, the angular application executes
http.post<LoginResponse>('/api/login', body)
which shows up in my browsers network trace as a post request to "http://localhost:8443/api/login".
I cannot find any info on this, only infos on how to handle tls when running the app with angular-cli.
Why does the app default to http, and where do I tell it to use https?
SSL key to use for serving HTTPS.
The HttpClient is used to perform HTTP requests and it imported form @angular/common/http. The HttpClient is more modern and easy to use the alternative of HTTP. HttpClient is an improved replacement for Http. They expect to deprecate Http in Angular 5 and remove it in a later version.
Angular offers HttpClient to work on API and handle data easily. In this approach HttpClient along with subscribe() method will be used for fetching data.
In the Angular documentation, they have an example where they use an interceptor to ensure https. The code snippet below is taken from their documentation:
// clone request and replace 'http://' with 'https://' at the same time
const secureReq = req.clone({
url: req.url.replace('http://', 'https://')
});
// send the cloned, "secure" request to the next handler.
return next.handle(secureReq);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With