You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[platform-server] vague error when entire URL is not provided for Http #15349
Current behavior
When calling a rest local rest API for example /api/getproducts, the server Http throws a vague error
ERROR { Error: Uncaught (in promise): Error at resolvePromise
Providing the entire URL fixes it: (but user would never know to do this)
this.http.get('http://localhost:5000/API/test')
Expected behavior
Previously (angular2-universal) we set the origin-URL for the user in these situations, so if we don't want to add that same behavior,
we need to make sure to Throw a more specific error letting the Dev know why the server didn't render that Http response. (Note the rest of the app actually renders it doesn't break rendering).
Also Docs should reflect whatever we decide to do here as well, to prevent confusion.
Minimal reproduction of the problem with instructions
this.http.get('/API/test')
What is the motivation / use case for changing the behavior?
Previous Users of Universal might be confused why his existing functionality doesn't work anymore, especially if not given a good Error message explaining it.
Well in Angular2-universal we assumed it was localhost if you didn't provide a full URL. The server doesn't handle relative URLs so the whole must be provided there.
In the providers you pass into the ngAspnetCoreEngine here, just pass in another Provider there, that has the Origin URL. Have all your Http calls prepend it automatically.
Most cases people are using external Rest endpoints anyway, it's not often they're served from the same location.
Activity
hheexx commentedon Mar 28, 2017
@MarkPieszak @alxhub
What is recommended way to do http now ?
why was angular2-universal solution of providing origin abandoned? Security?
I will probably inject host string with different values for browser/node and prepend it to all urls for now.
MarkPieszak commentedon Mar 28, 2017
Well in Angular2-universal we assumed it was localhost if you didn't provide a full URL. The server doesn't handle relative URLs so the whole must be provided there.
In the providers you pass into the ngAspnetCoreEngine here, just pass in another Provider there, that has the Origin URL. Have all your Http calls prepend it automatically.
Most cases people are using external Rest endpoints anyway, it's not often they're served from the same location.
hheexx commentedon Mar 28, 2017
That is exactly what I have done. Thanks.
PickRelated commentedon Jun 22, 2017
What about people using ngx-translate? It uses relative URL to get translation file.
P.S. the above solution does not work for me. Link is broken, so I have used hheexx's answer.
fix(platform-server): throw a better error message for relative URLs (a…
fix(platform-server): throw a better error message for relative URLs (a…
angular-automatic-lock-bot commentedon Sep 11, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.