mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 20:02:40 +08:00
feat(@angular/ssr): stabilize AngularNodeAppEngine
, AngularAppEngine
, and provideServerRouting
APIs
This commit promotes the `AngularNodeAppEngine`, `AngularAppEngine`, and `provideServerRouting` APIs from dev preview to stable. These APIs enhance server-side rendering (SSR) capabilities in Angular applications, improving routing and server integration for better performance and reliability.
This commit is contained in:
parent
b9591eb4b6
commit
cdfc50c29a
packages/angular/ssr
@ -18,8 +18,6 @@ import { createWebRequestFromNodeRequest } from './request';
|
|||||||
*
|
*
|
||||||
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
||||||
* application to ensure consistent handling of rendering requests and resource management.
|
* application to ensure consistent handling of rendering requests and resource management.
|
||||||
*
|
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export class AngularNodeAppEngine {
|
export class AngularNodeAppEngine {
|
||||||
private readonly angularAppEngine = new AngularAppEngine();
|
private readonly angularAppEngine = new AngularAppEngine();
|
||||||
|
@ -16,7 +16,6 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|||||||
* @param next - A callback function that signals the completion of the middleware or forwards the error if provided.
|
* @param next - A callback function that signals the completion of the middleware or forwards the error if provided.
|
||||||
*
|
*
|
||||||
* @returns A Promise that resolves to void or simply void. The handler can be asynchronous.
|
* @returns A Promise that resolves to void or simply void. The handler can be asynchronous.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export type NodeRequestHandlerFunction = (
|
export type NodeRequestHandlerFunction = (
|
||||||
req: IncomingMessage,
|
req: IncomingMessage,
|
||||||
@ -66,7 +65,6 @@ export type NodeRequestHandlerFunction = (
|
|||||||
* res.send('Hello from Fastify with Node Next Handler!');
|
* res.send('Hello from Fastify with Node Next Handler!');
|
||||||
* }));
|
* }));
|
||||||
* ```
|
* ```
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export function createNodeRequestHandler<T extends NodeRequestHandlerFunction>(handler: T): T {
|
export function createNodeRequestHandler<T extends NodeRequestHandlerFunction>(handler: T): T {
|
||||||
(handler as T & { __ng_node_request_handler__?: boolean })['__ng_node_request_handler__'] = true;
|
(handler as T & { __ng_node_request_handler__?: boolean })['__ng_node_request_handler__'] = true;
|
||||||
|
@ -23,7 +23,6 @@ import { fileURLToPath } from 'node:url';
|
|||||||
*
|
*
|
||||||
* @param url The URL of the module to check. This should typically be `import.meta.url`.
|
* @param url The URL of the module to check. This should typically be `import.meta.url`.
|
||||||
* @returns `true` if the provided URL represents the main entry point, otherwise `false`.
|
* @returns `true` if the provided URL represents the main entry point, otherwise `false`.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export function isMainModule(url: string): boolean {
|
export function isMainModule(url: string): boolean {
|
||||||
return url.startsWith('file:') && argv[1] === fileURLToPath(url);
|
return url.startsWith('file:') && argv[1] === fileURLToPath(url);
|
||||||
|
@ -27,7 +27,6 @@ const HTTP2_PSEUDO_HEADERS = new Set([':method', ':scheme', ':authority', ':path
|
|||||||
*
|
*
|
||||||
* @param nodeRequest - The Node.js request object (`IncomingMessage` or `Http2ServerRequest`) to convert.
|
* @param nodeRequest - The Node.js request object (`IncomingMessage` or `Http2ServerRequest`) to convert.
|
||||||
* @returns A Web Standard `Request` object.
|
* @returns A Web Standard `Request` object.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export function createWebRequestFromNodeRequest(
|
export function createWebRequestFromNodeRequest(
|
||||||
nodeRequest: IncomingMessage | Http2ServerRequest,
|
nodeRequest: IncomingMessage | Http2ServerRequest,
|
||||||
|
@ -19,7 +19,6 @@ import type { Http2ServerResponse } from 'node:http2';
|
|||||||
* @param source - The web-standard `Response` object to stream from.
|
* @param source - The web-standard `Response` object to stream from.
|
||||||
* @param destination - The Node.js response object (`ServerResponse` or `Http2ServerResponse`) to stream into.
|
* @param destination - The Node.js response object (`ServerResponse` or `Http2ServerResponse`) to stream into.
|
||||||
* @returns A promise that resolves once the streaming operation is complete.
|
* @returns A promise that resolves once the streaming operation is complete.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export async function writeResponseToNodeResponse(
|
export async function writeResponseToNodeResponse(
|
||||||
source: Response,
|
source: Response,
|
||||||
|
@ -19,8 +19,6 @@ import { joinUrlParts } from './utils/url';
|
|||||||
*
|
*
|
||||||
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
||||||
* application to ensure consistent handling of rendering requests and resource management.
|
* application to ensure consistent handling of rendering requests and resource management.
|
||||||
*
|
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export class AngularAppEngine {
|
export class AngularAppEngine {
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
* @param request - The incoming HTTP request object.
|
* @param request - The incoming HTTP request object.
|
||||||
* @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
|
* @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
|
||||||
* supporting both synchronous and asynchronous handling.
|
* supporting both synchronous and asynchronous handling.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export type RequestHandlerFunction = (
|
export type RequestHandlerFunction = (
|
||||||
request: Request,
|
request: Request,
|
||||||
@ -39,7 +38,6 @@ export type RequestHandlerFunction = (
|
|||||||
* const handler = toWebHandler(app);
|
* const handler = toWebHandler(app);
|
||||||
* export default createRequestHandler(handler);
|
* export default createRequestHandler(handler);
|
||||||
* ```
|
* ```
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction {
|
export function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction {
|
||||||
(handler as RequestHandlerFunction & { __ng_request_handler__?: boolean })[
|
(handler as RequestHandlerFunction & { __ng_request_handler__?: boolean })[
|
||||||
|
@ -24,7 +24,6 @@ const APP_SHELL_ROUTE = 'ng-app-shell';
|
|||||||
/**
|
/**
|
||||||
* Identifies a particular kind of `ServerRoutesFeatureKind`.
|
* Identifies a particular kind of `ServerRoutesFeatureKind`.
|
||||||
* @see {@link ServerRoutesFeature}
|
* @see {@link ServerRoutesFeature}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
enum ServerRoutesFeatureKind {
|
enum ServerRoutesFeatureKind {
|
||||||
AppShell,
|
AppShell,
|
||||||
@ -33,7 +32,6 @@ enum ServerRoutesFeatureKind {
|
|||||||
/**
|
/**
|
||||||
* Helper type to represent a server routes feature.
|
* Helper type to represent a server routes feature.
|
||||||
* @see {@link ServerRoutesFeatureKind}
|
* @see {@link ServerRoutesFeatureKind}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
interface ServerRoutesFeature<FeatureKind extends ServerRoutesFeatureKind> {
|
interface ServerRoutesFeature<FeatureKind extends ServerRoutesFeatureKind> {
|
||||||
ɵkind: FeatureKind;
|
ɵkind: FeatureKind;
|
||||||
@ -44,7 +42,6 @@ interface ServerRoutesFeature<FeatureKind extends ServerRoutesFeatureKind> {
|
|||||||
* Different rendering modes for server routes.
|
* Different rendering modes for server routes.
|
||||||
* @see {@link provideServerRouting}
|
* @see {@link provideServerRouting}
|
||||||
* @see {@link ServerRoute}
|
* @see {@link ServerRoute}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export enum RenderMode {
|
export enum RenderMode {
|
||||||
/** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
|
/** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
|
||||||
@ -61,7 +58,6 @@ export enum RenderMode {
|
|||||||
* Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
|
* Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
|
||||||
* This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
|
* This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
|
||||||
* @see {@link ServerRoutePrerenderWithParams}
|
* @see {@link ServerRoutePrerenderWithParams}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export enum PrerenderFallback {
|
export enum PrerenderFallback {
|
||||||
/**
|
/**
|
||||||
@ -85,7 +81,6 @@ export enum PrerenderFallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for server routes, providing shared properties.
|
* Common interface for server routes, providing shared properties.
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export interface ServerRouteCommon {
|
export interface ServerRouteCommon {
|
||||||
/** The path associated with this route. */
|
/** The path associated with this route. */
|
||||||
@ -101,7 +96,6 @@ export interface ServerRouteCommon {
|
|||||||
/**
|
/**
|
||||||
* A server route that uses Client-Side Rendering (CSR) mode.
|
* A server route that uses Client-Side Rendering (CSR) mode.
|
||||||
* @see {@link RenderMode}
|
* @see {@link RenderMode}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export interface ServerRouteClient extends ServerRouteCommon {
|
export interface ServerRouteClient extends ServerRouteCommon {
|
||||||
/** Specifies that the route uses Client-Side Rendering (CSR) mode. */
|
/** Specifies that the route uses Client-Side Rendering (CSR) mode. */
|
||||||
@ -111,7 +105,6 @@ export interface ServerRouteClient extends ServerRouteCommon {
|
|||||||
/**
|
/**
|
||||||
* A server route that uses Static Site Generation (SSG) mode.
|
* A server route that uses Static Site Generation (SSG) mode.
|
||||||
* @see {@link RenderMode}
|
* @see {@link RenderMode}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
|
export interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
|
||||||
/** Specifies that the route uses Static Site Generation (SSG) mode. */
|
/** Specifies that the route uses Static Site Generation (SSG) mode. */
|
||||||
@ -126,7 +119,6 @@ export interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'>
|
|||||||
* @see {@link RenderMode}
|
* @see {@link RenderMode}
|
||||||
* @see {@link ServerRoutePrerender}
|
* @see {@link ServerRoutePrerender}
|
||||||
* @see {@link PrerenderFallback}
|
* @see {@link PrerenderFallback}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
|
export interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
|
||||||
/**
|
/**
|
||||||
@ -171,7 +163,6 @@ export interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerende
|
|||||||
/**
|
/**
|
||||||
* A server route that uses Server-Side Rendering (SSR) mode.
|
* A server route that uses Server-Side Rendering (SSR) mode.
|
||||||
* @see {@link RenderMode}
|
* @see {@link RenderMode}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export interface ServerRouteServer extends ServerRouteCommon {
|
export interface ServerRouteServer extends ServerRouteCommon {
|
||||||
/** Specifies that the route uses Server-Side Rendering (SSR) mode. */
|
/** Specifies that the route uses Server-Side Rendering (SSR) mode. */
|
||||||
@ -181,7 +172,6 @@ export interface ServerRouteServer extends ServerRouteCommon {
|
|||||||
/**
|
/**
|
||||||
* Server route configuration.
|
* Server route configuration.
|
||||||
* @see {@link provideServerRouting}
|
* @see {@link provideServerRouting}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export type ServerRoute =
|
export type ServerRoute =
|
||||||
| ServerRouteClient
|
| ServerRouteClient
|
||||||
@ -221,7 +211,6 @@ export const SERVER_ROUTES_CONFIG = new InjectionToken<ServerRoutesConfig>('SERV
|
|||||||
*
|
*
|
||||||
* @see {@link ServerRoute}
|
* @see {@link ServerRoute}
|
||||||
* @see {@link withAppShell}
|
* @see {@link withAppShell}
|
||||||
* @developerPreview
|
|
||||||
*/
|
*/
|
||||||
export function provideServerRouting(
|
export function provideServerRouting(
|
||||||
routes: ServerRoute[],
|
routes: ServerRoute[],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user