Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@angular/build): utilize ssr.entry in Vite dev-server when available #28463

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

alan-agius4
Copy link
Collaborator

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

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.

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

export default createNodeRequestHandler(app);

Nest.js

const app = await NestFactory.create(AppModule);
export default createNodeRequestHandler(app);

Hono

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

Fastify

export default createNodeRequestHandler(async (req, res) => {
  await app.ready();
  app.server.emit('request', req, res);
});

… URL parameter

Modified the `HtmlTransformHandler` type to accept a context object containing a URL and HTML content. This change supports the `html:transform:pre` hook, enhancing the handler's capability to process transformations based on the request URL.
@alan-agius4 alan-agius4 force-pushed the dev-server-integration-ssr branch 2 times, most recently from 1dd5a11 to be51ae1 Compare September 20, 2024 14:30
@alan-agius4 alan-agius4 marked this pull request as ready for review September 20, 2024 14:34
@alan-agius4 alan-agius4 force-pushed the dev-server-integration-ssr branch 4 times, most recently from cb30910 to aad619f Compare September 20, 2024 14:55
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 20, 2024
@alan-agius4 alan-agius4 force-pushed the dev-server-integration-ssr branch 2 times, most recently from 036f598 to 07311d7 Compare September 23, 2024 10:05
…ilable

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.
…Handler `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);
});
```
Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

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

We should consider consolidating some of the E2E test logic here at some point.

Otherwise, LGTM.

@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 23, 2024
@alan-agius4 alan-agius4 merged commit 158774a into angular:main Sep 23, 2024
30 of 31 checks passed
@alan-agius4 alan-agius4 deleted the dev-server-integration-ssr branch September 23, 2024 20:34
@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 24, 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/build area: @angular/ssr detected: feature PR contains a feature commit target: major This PR is targeted for the next major release
Projects
None yet
2 participants