Skip to main content

TrpcFramework

@h4ad/serverless-adapter > TrpcFramework

(class) TrpcFramework

The framework that forwards requests to TRPC handler

Signature:

export declare class TrpcFramework<TContext extends TrpcAdapterBaseContext, TRouter extends AnyRouter = AnyRouter> implements FrameworkContract<TRouter> 

Implements: FrameworkContract <TRouter>

(constructor)

Default constructor

Signature:

constructor(options?: TrpcFrameworkOptions<TContext> | undefined);

Parameters

ParameterTypeDescription
optionsTrpcFrameworkOptions <TContext> | undefined(Optional)

(method) getSafeUrlForTrpc

Get safe url that can be used inside Trpc.

Signature:

protected getSafeUrlForTrpc(request: IncomingMessage): string;

Parameters

ParameterTypeDescription
requestIncomingMessageThe request object that will be forward to your app

Returns:

string

Example

const url = getSafeUrlForTrpc('/users?input=hello');
console.log(url); // users

(method) mergeDefaultContextWithOptionsContext

Merge the default context (TrpcAdapterContext ) with the context created by the user.

Signature:

protected mergeDefaultContextWithOptionsContext(createContextOptions: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>): TContext | Promise<TContext>;

Parameters

ParameterTypeDescription
createContextOptionsNodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>The options sent by trpc to create the context

Returns:

TContext | Promise<TContext>

(property) options

Signature:

protected readonly options?: TrpcFrameworkOptions<TContext> | undefined;

(method) sendRequest

Signature:

sendRequest<TRouter extends AnyRouter>(app: TRouter, request: IncomingMessage, response: ServerResponse): void;

Parameters

ParameterTypeDescription
appTRouter
requestIncomingMessage
responseServerResponse

Returns:

void

(method) wrapResolvedContextWithDefaultContext

Wraps the resolved context from the TrpcFrameworkOptions created with createContext and merge with the TrpcAdapterContext generated by the library.

Signature:

protected wrapResolvedContextWithDefaultContext(resolvedContext: TContext, createContextOptions: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>): TContext;

Parameters

ParameterTypeDescription
resolvedContextTContextThe context created with createContext inside TrpcFrameworkOptions
createContextOptionsNodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>The options sent by trpc to create the context

Returns:

TContext