9 Commits

Author SHA1 Message Date
Alan Agius
c33e862328 refactor(@angular/build): Enable SSR with Prerendering Disabled in Vite
This commit enables server-side rendering (SSR) in Vite when prerendering is turned off. It also imports `@angular/compiler` in the SSR middleware to resolve the following issue:

```
[vite] Internal server error: The injectable 'PlatformNavigation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.

The injectable is part of a library that has been partially compiled. However, the Angular Linker has not processed the library to utilize JIT compilation as a fallback.

Ideally, the library should be processed with the Angular Linker for complete AOT compilation.
```

Closes #28523
2024-10-02 15:08:03 +02:00
Alan Agius
f63072668e feat(@angular/build): utilize ssr.entry during prerendering to enable access to local API routes
The `ssr.entry` (server.ts file) is now utilized during prerendering, allowing access to locally defined API routes for improved data fetching and rendering.
2024-10-01 09:35:29 +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
bbc290133f feat(@angular/build): utilize ssr.entry in Vite dev-server when available
When `ssr.entry` (server.ts) is defined, Vite will now use it in the dev-server. This allows API and routes defined in `server.ts` to be accessible during development. This feature requires the new `@angular/ssr` APIs, which are currently in developer preview.
2024-09-23 22:34:55 +02:00
Alan Agius
fedeeb0a30 refactor(@angular/build): update SSR Vite middleware to utilize the enhanced API
Updated the SSR Vite middleware to align with the latest API improvements
2024-09-19 18:51:50 +02:00
Alan Agius
902dbf3a88 refactor(@angular/build): assign name to custom Vite middleware for better debugging
Naming the custom middleware improves the ability to identify middleware order during debugging.
2024-09-13 17:54:54 +02:00
Alan Agius
740c6486e2 refactor(@angular/build): implement custom middleware for header appending
Replaced multiple `appendServerConfiguredHeaders` calls with a single custom middleware to append headers to all responses, simplifying the code and ensuring consistency.
2024-09-13 17:54:54 +02:00
Alan Agius
1449c84c7d refactor(@angular/build): use new Angular SSR API
This commit introduces several key updates:
- Updates Vite middleware to utilize the new SSR API.
- Refactors prerendering, app-shell, and route extraction to align with the new rendering API.
- Generates manifest files required by the new SSR API.

**Note:** This is primarily a refactor; new features and improvements will be implemented in future updates.
2024-09-04 21:15:19 +02:00
Alan Agius
b5af8b59be refactor(@angular/build): move Vite middlewares into separate files
As the number of middlewares has increased over time, this commit enhances code health by relocating them into individual files.
2024-06-28 17:23:46 +02:00