@Inject(REQUEST) not available at angular side
See original GitHub issueI’m submitting a…
[ ] Regression [ ] Bug report [x] Feature request [x] Documentation issue or request [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
SSR does not provide the current host for DI.
Expected behavior
“request” should not be null in angular services.
constructor(private http: HttpClient,
@Optional() @Inject(REQUEST) private request: any,
@Inject(PLATFORM_ID) private platformId: Object) {
if (isPlatformServer(this.platformId)) {
console.log(this.request.get('host')); // host on the server
} else {
console.log(document.location.hostname); // host on the browser
}
}
What is the motivation / use case for changing the behavior?
Angular needs absolute urls at server side for api calls to the backend. See: https://angular.io/guide/universal#using-absolute-urls-for-server-requests
express-engine supports this as shown under “Request based Bootstrap”: https://github.com/angular/universal/blob/master/modules/express-engine/README.md
Environment
Nest version: 5.4.0
For Tooling issues:
- Node version: 8.9.4
- Platform: Windows
Others:
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
nguniversal express-engine request nullinjector - Stack Overflow
You can't access REQUEST in browser, it is server side object passed from expressjs to ng-universal . So in the worst case your...
Read more >Hierarchical injectors - Angular
With hierarchical dependency injection, you can isolate sections of the application and give them their own private dependencies not shared with the rest...
Read more >Server-side rendering (SSR) with Angular Universal
The following Node.js Express code routes all remaining requests to /dist , and returns a 404 - NOT FOUND error if the file...
Read more >Dependency injection in action - Angular
When a class requires a dependency, that dependency is added to the constructor as a parameter. When Angular needs to instantiate the class,...
Read more >Communicating with backend services using HTTP - Angular
Before working with the HttpClientModule , you should have a basic ... 0 requests made - .subscribe() not called. req.subscribe(); // 1 request...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems that this is still problem (v.4.0.1), REQUEST is null in ng component on ssr.
My app.component.ts
Providers for REQUEST and RESPONSE were removed in that commit https://github.com/nestjs/ng-universal/commit/b43e23fbc9031405937603a2f0ef4d9a82cd6d5d#diff-a721ebf1ae45ad7227e059567df31f08L39
my app is throwing expections on every reload, because my server doesnt get the cookies for Authentication