Reputation: 2043
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?
Upvotes: 6
Views: 12986
Reputation: 11
Just using https instead of http should be enough in angular 5+. Just make sure your server is properly configured for https and you are using the right https port. If you get "ERR_CERT_AUTHORITY_INVALID", put the troublesome link in the browser. When your access is prohibited, click on advanced, and then continue with unsafe access. This is only for testing on your local machine.
Upvotes: 0
Reputation: 314
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);
Upvotes: 6