I have a problem with Server Side Rendering of Angular 5 apps. I need domain to create proper link (app is used in different environments and it's bad idea to create few packages to each endpoint).
So I try to use option from stack, but always i get 127.0.0.1:4000 as a domain/host. I think that the best option should be:
server.ts
app.engine('html', (_, options, callback) => {
const engine = ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
{ provide: 'request', useFactory: () => options.req, deps: [] },
provideModuleMap(LAZY_MODULE_MAP)
]
});
engine(_, options, callback);
});
And in app.component.ts:
constructor(@Inject(PLATFORM_ID) private platformId,
private injector: Injector) {
if (isPlatformServer(this.platformId)) {
let req = this.injector.get('request');
console.log("host: " + req.get('host'));
} else {
console.log('we\'re rendering from the browser, there is no request object.');
}
}
I check also object option
from NodeJS -> it doesn't has any information about a domain. host
is defined there as 127.0.0.1:4000
. I doesn't has any idea how can I get it from NodeJS. Can you help or give small tips?
Maybe my fault is that I has wrong Nginx configuration?
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
server_name mock.test.com;
ssl_certificate /home/xxx/Projects/xsw/cert/certificate.chained.crt;
ssl_certificate_key /home/xxx/Projects/xsw/cert/key.prv;
root /home/xxx/Projects/xsw/;
index index.html;
location / {
proxy_pass http://127.0.0.1:4202;
}
}