21 Commits

Author SHA1 Message Date
cexbrayat
d77527db6d fix(@angular/ssr): export PrerenderFallback
Importing `PrerenderFallback` in a project throws at build time in 19.0.0-rc.2 with:

```ts
✘ [ERROR] No matching export in "node_modules/@angular/ssr/fesm2022/ssr.mjs" for import "PrerenderFallback"

    src/app/app.routes.server.ts:1:9:
      1 │ import { PrerenderFallback, RenderMode, ServerRoute } from '@angula...
```

This exports `PrerenderFallback` the same way `RenderMode` is exported to fix the issue.
2024-11-15 09:49:10 -08:00
Alan Agius
b2e2be052f refactor(@angular/ssr): remove RenderMode.AppShell in favor of new configuration option
This commit removes the `RenderMode.AppShell` option. Instead, a new configuration parameter, `{ appShellRoute: 'shell' }`, is introduced to the `provideServerRoutesConfig` method.

```ts
provideServerRoutesConfig(serverRoutes, { appShellRoute: 'shell' })
```
2024-11-08 19:51:35 +01:00
Alan Agius
18b6aea397 refactor(@angular/ssr): Add RequestHandlerFunction and NodeRequestHandlerFunction to public API
These additions are necessary to ensure their inclusion in adev.
2024-11-05 19:39:13 +01:00
Alan Agius
d6dfce105a refactor(@angular/ssr): add route configs to public API
These interfaces needs to be exported to be included in adev.
2024-10-31 16:55:05 +01:00
Alan Agius
1cacb8de15 refactor(@angular/ssr): export tokens from the /tokens entry point
This commit relocates the DI tokens to a dedicated entry point. This change ensures that we do not depend on tree-shaking to eliminate server code from client bundles.

Closes #28670
2024-10-21 18:37:36 +02:00
Alan Agius
65b6e75a5d fix(@angular/ssr): export RESPONSE_INIT, REQUEST, and REQUEST_CONTEXT tokens
This commit exports that the `RESPONSE_INIT`, `REQUEST`, and `REQUEST_CONTEXT` tokens.
2024-09-25 17:08:42 +02:00
Alan Agius
92209dd2e9 feat(@angular/ssr): add createRequestHandler and createNodeRequestHandler utilities
Introduced the `createRequestHandler` and `createNodeRequestHandler` utilities to expose middleware functions from the `server.ts` entry point for use with Vite.
This provides flexibility in integrating different server frameworks, including Express, Hono, and Fastify, with Angular SSR.

Examples:

**Express**
```ts
export default createNodeRequestHandler(app);
```

**Nest.js**
```ts
const app = await NestFactory.create(AppModule);
export default createNodeRequestHandler(app);
```

**Hono**
```ts
const app = new Hono();
export default createRequestHandler(app.fetch);
```

**Fastify**
```ts
export default createNodeRequestHandler(async (req, res) => {
  await app.ready();
  app.server.emit('request', req, res);
});
```
2024-09-23 22:34:55 +02: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
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
7d9ce246a3 refactor(@angular/ssr): remove singleton helpers
This commit removes the singleton helpers and instead exposes the
classes directly.
2024-09-06 07:13:04 +02:00
Alan Agius
30c25bf688 feat(@angular/ssr): export AngularAppEngine as public API
Added `AngularAppEngine` to the public API of `@angular/ssr`, allowing users to access it directly for enhanced server-side rendering functionality.
2024-08-28 07:51:27 +02:00
Alan Agius
4b09887a9c feat(@angular/ssr): move CommonEngine API to /node entry-point
Refactored the `CommonEngine` API import path to remove Node.js dependencies from the `@angular/ssr` main entry-point.

BREAKING CHANGE:

The `CommonEngine` API now needs to be imported from `@angular/ssr/node`.

**Before**
```ts
import { CommonEngine } from '@angular/ssr';
```

**After**
```ts
import { CommonEngine } from '@angular/ssr/node';
```
2024-08-27 08:57:37 +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
e9b057b39d refactor(@angular/build): remove route extractor and use version from @angular/ssr
Removed the route extractor from `@angular/build` and replaced it with the one from `@angular/ssr` for consistency and improved maintenance.
2024-08-14 16:42:24 +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
Charles Lyding
39f946a848 build: enabled isolated modules TypeScript option
The TypeScript `isolatedModules` option is now enabled for all TypeScript
code within the repository. As a result, all packages will now be built
with the option enabled. This does not affect projects created with the CLI
and is only related to the building of the actual Angular CLI code.
The `isolatedModules` option ensures that code can be emitted without the
TypeScript typechecker and allows tools other than TypeScript to potentially
be used. Code was updated to correct all errors after the option was enabled.
Additionally, some early code fixes were done to add function and accessor
return types to prepare for future `isolatedDeclarations` usage. More changes
would be needed to consider turning on `isolatedDeclarations`, however.
2024-06-23 15:34:49 +02:00
Ash Ramirez
434a3740f0 refactor(@angular/cli): update aio links -> adev links
Updates for all angular.io links to the new angular.dev domain. Additionally, adjustment to new resources where the equivalent does not exist on the new site (e.g. Tour of Heroes tutorial)
2024-06-06 11:12:06 +02:00
Alan Agius
dcf3fddff2 feat(@angular/ssr): add performance profiler to CommonEngine
This commit adds an option to the `CommonEngine` to enable performance profiling. When enabled, timings of a number of steps will be outputted in the server console.

Example:
```
********** Performance results **********
Retrieve SSG Page:       0.3ms
Render Page:             25.4ms
Inline Critical CSS:     2.3ms
*****************************************
```

To enable profiling set `enablePeformanceProfiler: true` in the `CommonEngine` options.

```ts
const commonEngine = new CommonEngine({
  enablePeformanceProfiler: true
});
```
2023-09-28 17:32:29 +02:00
Alan Agius
c30e3692b3 refactor(@angular/ssr): remove express engine
This removes the util function for express, instead the "CommonEngine" is called directly infuture before this package is final we might rename the "CommonEngine" to something else.
2023-08-30 09:53:57 +02:00
Alan Agius
3fe432c71b refactor: update code to integrate universal repo
This commit updates the moved universal code into the cli pipeline
2023-08-22 20:44:53 +00:00
Alan Agius
e6ce7f8414 refactor: prepare code for CLI move 2023-08-16 09:55:58 +00:00