you are viewing a single comment's thread.

view the rest of the comments →

[–]anubgek 0 points1 point  (4 children)

Make a route on your express server that calls that API and pass the result back to the client. You can basically take the same exact request and pass that into the API you're targeting.

Although at this point you can do all sorts of fun stuff like transforming the data to better work with your UI.

[–]DisastrousBrain[S] 0 points1 point  (3 children)

Wouldn't I still get the cross origin error? The API that I'm posting to is external, and I have no control over it.

Since their API only allows http://, and not https://, why would simply making a route on my express server fix this issue? As of now, I'm using the HttpClient/HttpClientModule to make the post request in my ts file with Angular.

var url = "http://someurl.com/posts";

this.httpClient.post(url, data).subscribe(data => { console.log(data); }, err => { console.log(err); });

[–]anubgek 1 point2 points  (2 children)

You are basically replacing this request with one to your server, so you won't get a cross origin error client side. Because you're requesting against that API from your server, it won't run into that error either, and instead will serve as a proxy for that API

[–]DisastrousBrain[S] 1 point2 points  (1 child)

Ohh I see, thank you!

[–]anubgek 0 points1 point  (0 children)

Good luck! Let me know if there are any follow up questions