Dynamic base href (APP_BASE_HREF) for SSR

Ouverte
#29,449 6 commentaires 11 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
angular, typescript
Domaine
backend, web-dev

Piste de recherche

Commencez par lire AngularNodeAppEngine.handle et comparez sa gestion de base-href avec le comportement existant de CommonEngine et ngExpressEngine. Suivez le chemin par lequel APP_BASE_HREF et la requête parviennent au rendu SSR, puis définissez ce que nécessiterait la prise en charge d’un base href spécifique à la requête. Le travail est terminé lorsque la sortie SSR peut utiliser le base href fourni par la requête sans analyser manuellement le fichier index.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

area: @angular/ssr feature feature: insufficient votes
Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

I'm using Angular as SSR multi tenant app.

We differentiate the clients per domain.

exemple:
potato.com/portal
tomato.com/citizen
onion-tickets.com

The majority from our clients use a specific base href and just a few serve the app on the root.

Right now it's difficult to work with angular with this setup, I had to do some 'stuff' on the SSR server to make it work.

We use a similar configuration for development too because it's easy to use domains rather than keep changing the client for localhost. This also allows to have many clients configured at the same time.

For the development we simply add on the OS hosts file [CLIENT].local and have nginx running on docker.
This has sped up a lot of developing time.

We are migrating from angular 16 to 19 and already preparing for the AngularNodeAppEngine because from what I saw in the docs it will be the default instead of the ngExpressEngine and CommonEngine.

At the moment there are (what I believe is regression) some things that worked in v16 that don't work in v19, and it impacts production and development.

I was preparing a repo with an example app to list those problems, but later realized that if the APP_BASE_HREF doesn't work like before, none of the other stuff matters.

This is part of the code that we use to make it work.

// this will garantee that all the js are served from the right routes.
if (condition) {
  res.render(indexHtml, {
    req,
    document: docWithoutBaseHref
  });
} else {
  res.render(indexHtml, {
    req,
    providers: [{ provide: APP_BASE_HREF, useValue: clientBaseHref }],
    document: docWithBaseHref
  })
}

As you can see by the name of the variables docWithoutBaseHref and docWithBaseHref we also manually parse the index file to add and remove the base href according to the domain and base href from the request.

I look it up in the code for v19 and the base href is retrieved from the html generated on the bundling process by the .handle(req) method from AngularNodeAppEngine, this break our app because we need to put the base href that came from the SSR request, instead of reading from a static file.

Is there a possibility to have this again working with Angular?

We tested with commonEngine and it has the same capabilities from ngExpressEngine.

The problem is that I don't think the angular team will maintain multiple packages, considering that the Server routes it's supported only by AngularNodeAppEngine and it will be the future of angular SSR and the other options will be deprecated.

We would like to know if something like this will be considered to be supported by AngularNodeAppEngine?

We can still keep using the packages/code that allow our customization, but this will only delay the problem and will force us to stay attached to an older version of angular. And prevent the use of new features.

We rely on this information to make a decision about how to move forward.

Thanks.
Cheers.

Proposed solution

Allow for customization of html files from the SSR server instead of using hard coded values.
Allow to provide dynamic base href from SSR to the rendering of an angular route.

Alternatives considered

Keep using an older angular version and never upgrade.
Move to another framework.

Langage dominant
TypeScript
Étoiles
27k
Forks
11.8k
Merge moyen
16 h 35 min
PR mergées (30 j)
176

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de angular/angular-cli

Toutes les issues de angular/angular-cli

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.