Skip to content

Commit

Permalink
refactor(@angular/ssr): Add RequestHandlerFunction and `NodeRequest…
Browse files Browse the repository at this point in the history
…HandlerFunction` to public API

These additions are necessary to ensure their inclusion in adev.

(cherry picked from commit 18b6aea)
  • Loading branch information
alan-agius4 committed Nov 5, 2024
1 parent e4df756 commit a568f19
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions goldens/public-api/angular/ssr/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export enum RenderMode {
Server = 1
}

// @public
export type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;

// @public
export type ServerRoute = ServerRouteAppShell | ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;

Expand Down
5 changes: 4 additions & 1 deletion goldens/public-api/angular/ssr/node/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ export interface CommonEngineRenderOptions {
}

// @public
export function createNodeRequestHandler<T extends RequestHandlerFunction>(handler: T): T;
export function createNodeRequestHandler<T extends NodeRequestHandlerFunction>(handler: T): T;

// @public
export function createWebRequestFromNodeRequest(nodeRequest: IncomingMessage): Request;

// @public
export function isMainModule(url: string): boolean;

// @public
export type NodeRequestHandlerFunction = (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => Promise<void> | void;

// @public
export function writeResponseToNodeResponse(source: Response, destination: ServerResponse): Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion packages/angular/ssr/node/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export {

export { AngularNodeAppEngine } from './src/app-engine';

export { createNodeRequestHandler } from './src/handler';
export { createNodeRequestHandler, type NodeRequestHandlerFunction } from './src/handler';
export { writeResponseToNodeResponse } from './src/response';
export { createWebRequestFromNodeRequest } from './src/request';
export { isMainModule } from './src/module';
5 changes: 3 additions & 2 deletions packages/angular/ssr/node/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ 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.
*
* @returns A Promise that resolves to void or simply void. The handler can be asynchronous.
* @developerPreview
*/
type RequestHandlerFunction = (
export type NodeRequestHandlerFunction = (
req: IncomingMessage,
res: ServerResponse,
next: (err?: unknown) => void,
Expand Down Expand Up @@ -67,7 +68,7 @@ type RequestHandlerFunction = (
* ```
* @developerPreview
*/
export function createNodeRequestHandler<T extends RequestHandlerFunction>(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;

return handler;
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/ssr/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export * from './private_export';

export { AngularAppEngine } from './src/app-engine';
export { createRequestHandler } from './src/handler';
export { createRequestHandler, type RequestHandlerFunction } from './src/handler';

export {
type PrerenderFallback,
Expand Down
5 changes: 4 additions & 1 deletion packages/angular/ssr/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
* @param request - The incoming HTTP request object.
* @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
* supporting both synchronous and asynchronous handling.
* @developerPreview
*/
type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
export type RequestHandlerFunction = (
request: Request,
) => Promise<Response | null> | null | Response;

/**
* Annotates a request handler function with metadata, marking it as a special
Expand Down

0 comments on commit a568f19

Please sign in to comment.