@fal-ai/serverless-proxy
Version:
Deprecation note: this library has been deprecated in favor of @fal-ai/server-proxy
32 lines (31 loc) • 1.55 kB
TypeScript
export declare const TARGET_URL_HEADER = "x-fal-target-url";
export declare const DEFAULT_PROXY_ROUTE = "/api/fal/proxy";
export type HeaderValue = string | string[] | undefined | null;
/**
* The proxy behavior that is passed to the proxy handler. This is a subset of
* request objects that are used by different frameworks, like Express and NextJS.
*/
export interface ProxyBehavior<ResponseType> {
id: string;
method: string;
respondWith(status: number, data: string | any): ResponseType;
sendResponse(response: Response): Promise<ResponseType>;
getHeaders(): Record<string, HeaderValue>;
getHeader(name: string): HeaderValue;
sendHeader(name: string, value: string): void;
getRequestBody(): Promise<string | undefined>;
resolveApiKey?: () => Promise<string | undefined>;
}
/**
* A request handler that proxies the request to the fal-serverless
* endpoint. This is useful so client-side calls to the fal-serverless endpoint
* can be made without CORS issues and the correct credentials can be added
* effortlessly.
*
* @param behavior the request proxy behavior.
* @returns Promise<any> the promise that will be resolved once the request is done.
*/
export declare function handleRequest<ResponseType>(behavior: ProxyBehavior<ResponseType>): Promise<ResponseType>;
export declare function fromHeaders(headers: Headers): Record<string, string | string[]>;
export declare const responsePassthrough: (res: Response) => Promise<Response>;
export declare const resolveApiKeyFromEnv: () => Promise<string>;