question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Universal REQUEST and RESPONSE

See original GitHub issue

Note: for support questions, please use one of [these channels][Channels]. This repository’s issues are reserved for feature requests and bug reports. Also, Preboot has moved [here][preboot] - please make preboot-related issues there.

  • I’m submitting a …
- [x ] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
  • What modules are related to this Issue?
- [ ] aspnetcore-engine
- [ ] common
- [x ] express-engine
- [ ] hapi-engine
- [ ] module-map-ngfactory-loader
  • What is the current behavior? How to access to REQUEST and RESPONSE objects from angular components or services ??

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
robinComacommented, Jun 13, 2018

Hello all,

I have the same error, this.response is empty :

import { Component, OnInit, Optional, Inject, PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { RESPONSE } from '@nguniversal/express-engine/tokens';

@Component({
  selector: 'placeme-not-found',
  templateUrl: './not-found.component.html',
  styleUrls: ['./not-found.component.scss']
})
export class NotFoundComponent implements OnInit {

  constructor(
    @Inject(PLATFORM_ID) private platformId: Object,
    @Optional() @Inject(RESPONSE) private response: any
  ) { }

  ngOnInit() {
    if (isPlatformServer(this.platformId)) {
      this.response.sendStatus(404);
    }
  }

}
app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));
"@angular-devkit/build-angular": "~0.6.3",
"@angular/animations": "^6.0.2",
"@angular/cdk": "^6.1.0",
"@angular/cli": "~6.0.3",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/compiler-cli": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/flex-layout": "^6.0.0-beta.15",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/language-service": "^6.0.2",
"@angular/material": "^6.1.0",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/platform-server": "^6.0.2",
"@angular/router": "^6.0.2",
"@google-cloud/datastore": "^1.4.0",
"@nguniversal/common": "^6.0.0",
"@nguniversal/express-engine": "^6.0.0",
"@nguniversal/module-map-ngfactory-loader": "^6.0.0",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
2reactions
robinComacommented, Jun 13, 2018

My bad 😃

I solve it by changing :

app.get('*', (req, res) => {
  res.render('index', { req });
});

by

app.get('*', (req, res) => {
  res.render('index', { req, res });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering (SSR) with Angular Universal
Here, "request URL" refers to the URL of the request as a response to which the application is being rendered on the server....
Read more >
Angular Universal: Complete Practical Guide
This post will be a complete practical guide for getting started with Angular Universal. We are going to go start with an existing...
Read more >
Can Angular Universal perform http requests from the server ...
Can Angular Universal render a page on the server that fetches data via HTTPClient requests so that the browser does not make those...
Read more >
Angular Universal: real app problems - InDepth.Dev
The server sends this HTML as a response to the GET request. Angular application on the server is destroyed after rendering.
Read more >
Build faster JavaScript Web Apps with Angular Universal, a ...
You can build SEO-friendly Angular apps with Angular Universal. ... We will use the key-value pair to store or retrieve the request response, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found