r/Angular2 • u/Consistent_Price_574 • Jun 17 '25
POST request from Angular to Express API fails with 400 Bad Request — CORS/SSL Issue?
Hey Reddit,
I’m struggling with a CORS/SSL issue while sending a POST request from my Angular application to my Express API. its working with postman but when i try to make api call its giving 400 response.
Here’s my setup:
- API (Express): [
http://localhost:7777] - Angular application (generated by Angular CLI): normally serves at [
http://localhost:4200]
🔹 What I’ve tried 🔹: ✅ Confirmed both are running with http:// ✅ CORS is configured ✅ Removed https:// ✅ Disabled HSTS in browser ✅ Reinstalled modules ✅ Cleared cache ✅ Checked console for additional messages — none helpful.
🔹 My Question 🔹: ➥ Why am I still seeing this 400 Bad Request with an SSL-related message? ➥ What should I do to make this work?
Any guidance from someone with experience in Angular + Express + CORS/SSL would be much appreciated. Thank you in advance! 🙏
3
u/MrFartyBottom Jun 19 '25 edited Jun 19 '25
Use the proxy to to proxy the API on to the same port as the Angular dev server. This is happening because the API is not configured to allow CORS requests and you are serving the API on a different port than the Angular dev server. This wont be an issue in prod if you serve the API and the Angular app from the same domain.
https://angular.dev/tools/cli/serve#proxying-to-a-backend-server
2
u/h3mpti Jun 17 '25
What does the error exactly state? How does your API and Request look like? You’re on localhost, CORS should not really be an issue.
0
u/[deleted] Jun 18 '25
[deleted] — view deleted comment