Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
Angular Universal get host name and origin url to call api

I have added Angular Universal in my project and everything was working fine. But now we need mapping for subdomain in our application. For that I need to access the host name and current url to pass this parameters in api. But I am not able to get it on server side.

I have already tried below urls

Get hostname and pathname information within Angular Universal

How do I get the hostname Angular Universal v9.x

Angular Universal get domain name: Property 'req' does not exist on type 'object'

Below is my code in server.ts server.ts

 // All regular routes use the Universal engine
  server.get('*', (req, res) => {
    res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl },
      { provide: 'host', useValue: req.get('host') }] });
  });

Component.ts

constructor(
 private businessService: BuisnessService,
    @Inject(PLATFORM_ID) private platformId: any,
    @Optional() @Inject('host') private host: any,
    @Optional() @Inject(Request) private request: any,
     private injector: Injector
){
 console.log(`body`, host); //getting null
}

ngOnInit(): void {
if (isPlatformServer(this.platformId)) {
      console.log(this.injector.get('host'))  //not working
      console.log(this.request,this.host)     //not working
    } else {

      console.log('document: ', document.location.hostname);

    }
 this.getDomainInfo(hostname,currentUrl)  // how do I get current url and hostname on server side.
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda