Skip to content

Commit

Permalink
fix(@angular/ssr): include requestContext in RequestHandlerFunction
Browse files Browse the repository at this point in the history
Added the missing `requestContext` parameter to the `RequestHandlerFunction`.
  • Loading branch information
alan-agius4 committed Nov 5, 2024
1 parent 4633562 commit 2e89244
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 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, requestContext?: unknown) => 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';
6 changes: 4 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,10 @@ 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 +69,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
10 changes: 8 additions & 2 deletions packages/angular/ssr/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
/**
* Function for handling HTTP requests in a web environment.
*
* @param request - The incoming HTTP request object.
* @param request - The incoming HTTP request object
* @param requestContext - Optional additional context for rendering, such as request metadata.
* @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,
requestContext?: unknown,
) => Promise<Response | null> | null | Response;

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

0 comments on commit 2e89244

Please sign in to comment.