@fal-ai/server-proxy
Version:
The fal.ai server proxy adapter for JavaScript and TypeScript Web frameworks
44 lines (43 loc) • 2.3 kB
TypeScript
import { type ProxyConfig } from "./config";
import type { ProxyBehavior } from "./types";
export { createUrlMatcher, DEFAULT_ALLOWED_URL_PATTERNS, resolveProxyConfig, type ProxyConfig, } from "./config";
export { type HeaderValue, type ProxyBehavior } from "./types";
export declare const TARGET_URL_HEADER = "x-fal-target-url";
export declare const DEFAULT_PROXY_ROUTE = "/api/fal/proxy";
/**
* Checks if a URL matches any of the allowed URL patterns.
*
* @param url the URL to check (without scheme, e.g., "fal.run/path").
* @param patterns the allowed URL patterns (glob-style). If not provided, uses default patterns.
* @returns whether the URL is allowed.
*/
export declare function isAllowedUrl(url: string, patterns?: string[]): boolean;
/**
* Extracts the endpoint from a URL (path without leading slash).
* @param targetUrl the full URL including scheme.
* @returns the endpoint (path without leading slash).
*/
export declare function getEndpoint(targetUrl: string): string;
/**
* Checks if an endpoint matches any of the allowed endpoint patterns.
*
* @param endpoint the endpoint to check (path without leading slash).
* @param patterns the allowed endpoint patterns (glob-style).
* @returns whether the endpoint is allowed.
*/
export declare function isAllowedEndpoint(endpoint: string, patterns: string[]): boolean;
/**
* A request handler that proxies the request to the fal API
* endpoint. This is useful so client-side calls to the fal endpoint
* can be made without CORS issues and the correct credentials can be added
* effortlessly.
*
* @param behavior the request proxy behavior.
* @param config the proxy configuration. Can be a partial config (will be resolved internally)
* or a pre-resolved config from `resolveProxyConfig` to avoid per-request warnings.
* @returns Promise<any> the promise that will be resolved once the request is done.
*/
export declare function handleRequest<ResponseType>(behavior: ProxyBehavior<ResponseType>, config?: Partial<ProxyConfig> | ProxyConfig): 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>;