15 Commits

Author SHA1 Message Date
Alan Agius
ad1d7d76fc fix(@angular/ssr): ensure correct Location header for redirects behind a proxy
Previously, when the application was served behind a proxy, server-side redirects generated an incorrect Location header, causing navigation issues. This fix updates `createRequestUrl` to use the port from the Host header, ensuring accurate in proxy environments. Additionally, the Location header now only contains the pathname, improving compliance with redirect handling in such setups.

Closes #29151
2024-12-17 12:33:49 -08:00
Alan Agius
6647247ec0 test(@angular/ssr): refine spec setup to resolve component ID collision warnings
This update addresses excessive log noise caused by the following warning:
`NG0912: Component ID generation collision detected. Components 'AppComponent' and 'AppComponent' with selector 'app-root' generated the same component ID. To fix this, you can change the selector of one of those components or add an extra host attribute to force a different ID. Find more at https://angular.dev/errors/NG0912`.
2024-12-06 08:24:11 +01:00
Alan Agius
aed726fca3 fix(@angular/build): add timeout to route extraction
This commit introduces a 30-second timeout for route extraction.
2024-11-27 16:48:33 -05:00
Alan Agius
34574b2906 fix(@angular/ssr): handle nested redirects not explicitly defined in router config
This commit ensures proper handling of nested redirects that are implicitly structured but not explicitly defined in the router configuration.

Closes #28903
2024-11-22 11:10:34 +01:00
Alan Agius
e16cbb9ad5 refactor(@angular/ssr): remove duplicate code and streamline functionality
This commit cleans up duplicate code left from the previous implementations of process, serve, and render. Additionally, prerender serve now exclusively handles HEAD and GET requests, aligning with updated handling requirements. The private `renderStatic` method has been removed in favor of the `handle` method for improved maintainability.
2024-11-06 10:14:07 +01:00
Alan Agius
505521e546 perf(@angular/ssr): integrate ETags for prerendered pages
When using the new developer preview API to serve prerendered pages, ETags are added automatically, enabling efficient caching and content validation for improved performance.
2024-11-01 19:52:03 +01:00
Alan Agius
481ccdbc5a fix(@angular/ssr): enable serving of prerendered pages in the App Engine
This commit implements the capability for the App Engine to serve prerendered pages directly. Previously, we relied on frameworks like Express for this functionality, which resulted in inconsistent redirects for directories where in some cases a trailing slash was added to the route.

**Note:** This change applies only when using the new SSR APIs. When using the `CommonEngine`, a 3rd party static serve middleware is still required.
2024-11-01 10:45:05 +01:00
Alan Agius
3b00fc908d feat(@angular/build): introduce outputMode option to the application builder
The `outputMode` option accepts two values:
- **`static`:**  Generates a static output (HTML, CSS, JavaScript) suitable for deployment on static hosting services or CDNs. This mode supports both client-side rendering (CSR) and static site generation (SSG).
- **`server`:** Generates a server bundle in addition to static assets, enabling server-side rendering (SSR) and hybrid rendering strategies. This output is intended for deployment on a Node.js server or serverless environment.

- **Replaces `appShell` and `prerender`:**  The `outputMode` option simplifies the CLI by replacing the `appShell` and `prerender` options when server-side routing is configured.
- **Controls Server API Usage:**  `outputMode` determines whether the new server API is utilized. In `server` mode, `server.ts` is bundled as a separate entry point, preventing direct references to `main.server.ts` and excluding it from localization.

Closes #27356, closes #27403, closes #25726, closes #25718 and closes #27196
2024-09-19 21:29:34 +02:00
Alan Agius
2640bf7a68 fix(@angular/ssr): correct route extraction and error handling
This commit introduces the following changes:
- Disallows paths starting with a slash to match Angular router behavior.
- Errors are now stored and displayed at a later stage, improving UX by avoiding unnecessary stack traces that are not useful in this context.
2024-09-16 21:22:10 +02:00
Alan Agius
d66aaa3ca4 feat(@angular/ssr): add server routing configuration API
This commit introduces a new server routing configuration API, as discussed in RFC https://github.com/angular/angular/discussions/56785. The new API provides several enhancements:

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/error',
    renderMode: RenderMode.Server,
    status: 404,
    headers: {
      'Cache-Control': 'no-cache'
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    async getPrerenderPaths() {
      const dataService = inject(ProductService);
      const ids = await dataService.getIds(); // Assuming this returns ['1', '2', '3']
      return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }]
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    fallback: PrerenderFallback.Server, // Can be Server, Client, or None
    async getPrerenderPaths() {
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Server,
  },
  {
    path: '/error',
    renderMode: RenderMode.Client,
  },
  {
    path: '/**',
    renderMode: RenderMode.Prerender,
  },
];
```

These additions aim to provide greater flexibility and control over server-side rendering configurations and prerendering behaviors.
2024-09-12 19:59:05 +02:00
Alan Agius
76de1bfff1 test: update ssr UT to zoneless
This commit updates the UT tests to zoneless.
2024-08-30 09:49:40 -07:00
Alan Agius
9692a9054c feat(@angular/ssr): improve handling of aborted requests in AngularServerApp
Introduce support for handling request signal abortions in the `AngularServerApp`. This is particularly useful in the development server integration where a 30-second timeout is enforced for requests/responses.
2024-08-21 18:46:03 +02:00
Alan Agius
1c185183c3 refactor(@angular/ssr): expose private APIs for build system integration and refactor app management
- Exposed several utility functions as private APIs to support the integration with the build system.
- Removed `isDevMode` and caching logic from `AngularAppEngine`. This was necessary to better handle updates when using Vite. Instead, `AngularServerApp` is now treated as a singleton to simplify management.
- Switched asset storage from an `Object` to a `Map` in the manifest for improved efficiency and consistency.

This refactor sets the groundwork for seamless wiring with the build system.
2024-08-21 09:30:01 +02:00
Alan Agius
bca5683893 feat(@angular/ssr): dynamic route resolution using Angular router
This enhancement eliminates the dependency on file extensions for server-side rendering (SSR) route handling, leveraging Angular's router configuration for more dynamic and flexible route determination. Additionally, configured redirectTo routes now correctly respond with a 302 redirect status.

The new router uses a radix tree for storing routes. This data structure allows for efficient prefix-based lookups and insertions, which is particularly crucial when dealing with nested and parameterized routes.

This change also lays the groundwork for potential future server-side routing configurations, further enhancing the capabilities of Angular's SSR functionality.
2024-08-14 11:05:12 +02:00
Alan Agius
3c9697a8c3 feat(@angular/ssr): introduce new hybrid rendering API
This commit introduces the new hybrid rendering API for Angular's Server-Side Rendering (SSR). The API aims to enhance the flexibility of SSR as discussed in https://github.com/angular/angular/discussions/56785

- This API is currently not accessible.
- Additional work is required in the Angular CLI to:
  - Wire up the manifest.
  - Integrate other necessary components.
2024-08-09 09:36:54 +02:00