angular: Custom Http not working with SSR
I’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When you create custom Http
it is working in browser, but when you use it in NodeJs environment while rendering on server it never performs HttpRequest
.
Expected behavior
Custom Http
should work on browser or server side.
Minimal reproduction of the problem with instructions
https://github.com/kukjevov/ng-universal-demo You can see it in master branch. There is a custom Http
which works on client, but not on server.
There are console logs, but log in subscribe
method which prints result is only called on browser side if used with custom Http
. If you use original Http
log is also called on server and data are rendered to html.
From logs you can see that custom GET
method is called but that is all. You cant even see
GET: /data: 3.005ms
on server side if custom Http
is used. So that means url was never called.
–>
Please tell us about your environment: Win 10, VSCode, Express Server
-
Angular version: 4.0.0-rc.5
-
Browser: [all]
-
Language: [TypeScript 2.2.1]
-
Node (for AoT issues):
node --version
= 7.7.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 16 (9 by maintainers)
Hello.
I cant say it was solved, because solution is “borrow” code from your code, so it is more like workaround, but it is working. Since i see, that you dont want to do anything about it we can keep it closed.
But problem with this “solution” is if you change your code it will not reflect changes in our code, so updating zone.js, or angular can break code without knowing that.
Well i did some deeper investigation and it looks like different problem.
Actually Http calls runs as expected, but this code:
which renders html runs before async http operation finish. It simply does not wait for this operation to finish. Interesting is that this is not problem with original HTTP, but with custom HTTP it happens in wrong order. That is reason why you dont see results of http requests rendered from server side.