Skip to content

Conversation

alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Sep 3, 2024

feat(@angular/ssr): Add getHeaders Method to AngularAppEngine and AngularNodeAppEngine for handling pages static headers

This commit introduces a new getHeaders method to the AngularAppEngine and AngularNodeAppEngine classes, designed to facilitate the retrieval of HTTP headers based on URL pathnames for statically generated (SSG) pages.

const angularAppEngine = new AngularNodeAppEngine();

app.use(express.static('dist/browser', {
  setHeaders: (res, path) => {
    // Retrieve headers for the current request
    const headers = angularAppEngine.getHeaders(res.req);

    // Apply the retrieved headers to the response
    for (const { key, value } of headers) {
      res.setHeader(key, value);
    }
  }
}));

In this example, the getHeaders method is used within an Express application to dynamically set HTTP headers for static files. This ensures that appropriate headers are applied based on the specific request, enhancing the handling of SSG pages.


feat(@angular/ssr): introduce AngularNodeAppEngine API for Node.js integration

Expose a variant of AngularAppEngine tailored for Node.js. These additions streamline the process by minimizing boilerplate code and eliminate the need for users to call createWebRequestFromNodeRequest before invoking the render method.

@alan-agius4 alan-agius4 added the target: major This PR is targeted for the next major release label Sep 3, 2024
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Sep 3, 2024
@alan-agius4 alan-agius4 changed the title Create node app feat: add getHeaders method to AngularAppEngine and AngularNodeAppEngine for handling pages static headers Sep 3, 2024
@alan-agius4 alan-agius4 force-pushed the create-node-app branch 2 times, most recently from f0cfdca to bf3c9d2 Compare September 3, 2024 09:04
@alan-agius4 alan-agius4 changed the title feat: add getHeaders method to AngularAppEngine and AngularNodeAppEngine for handling pages static headers feat(@angular/ssr): add getHeaders method to AngularAppEngine and AngularNodeAppEngine for handling pages static headers Sep 3, 2024
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 3, 2024
@alan-agius4 alan-agius4 requested a review from dgp1130 September 3, 2024 09:05
@alan-agius4 alan-agius4 marked this pull request as ready for review September 3, 2024 09:05
@alan-agius4 alan-agius4 force-pushed the create-node-app branch 4 times, most recently from 64b6ffa to 1a1fd33 Compare September 3, 2024 09:16
Copy link
Collaborator

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, lots of little comments just to make sure I understand the use case and how this fits into the architecture.

@alan-agius4 alan-agius4 force-pushed the create-node-app branch 7 times, most recently from b9caedd to 225436b Compare September 4, 2024 17:27
…integration

Expose a variant of `AngularAppEngine` tailored for Node.js. These additions streamline the process by minimizing boilerplate code and eliminate the need for users to call `createWebRequestFromNodeRequest` before invoking the render method.
… `AngularNodeAppEngine` for handling pages static headers

This commit introduces a new `getHeaders` method to the `AngularAppEngine` and `AngularNodeAppEngine` classes, designed to facilitate the retrieval of HTTP headers based on URL pathnames for statically generated (SSG) pages.

```typescript
const angularAppEngine = new AngularNodeAppEngine();

app.use(express.static('dist/browser', {
  setHeaders: (res, path) => {
    // Retrieve headers for the current request
    const headers = angularAppEngine.getHeaders(res.req);

    // Apply the retrieved headers to the response
    for (const { key, value } of headers) {
      res.setHeader(key, value);
    }
  }
}));
```

In this example, the `getHeaders` method is used within an Express application to dynamically set HTTP headers for static files. This ensures that appropriate headers are applied based on the specific request, enhancing the handling of SSG pages.
This commit removes the singleton helpers and instead exposes the
classes directly.
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 6, 2024
@alan-agius4 alan-agius4 merged commit 7d9ce24 into angular:main Sep 6, 2024
30 checks passed
@alan-agius4 alan-agius4 deleted the create-node-app branch September 6, 2024 05:13
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants