@fal-ai/server-proxy
Version:
The fal.ai server proxy adapter for JavaScript and TypeScript Web frameworks
58 lines (57 loc) • 2.11 kB
TypeScript
import { type NextRequest } from "next/server";
import type { NextApiHandler } from "next/types";
import { ProxyConfig } from "./config";
/**
* The default Next API route for the fal.ai client proxy.
*/
export declare const PROXY_ROUTE = "/api/fal/proxy";
/**
* Creates a page router handler that proxies requests to the fal API.
*
* This is a drop-in handler for Next.js applications so that the client can be called
* directly from the client-side code while keeping API keys safe.
*
* @param config the proxy options.
* @returns a Next.js page router handler function.
*/
export declare const createPageRouterHandler: (config?: Partial<ProxyConfig>) => NextApiHandler;
/**
* The Next API route handler for the fal.ai client proxy.
* Use it with the /pages router in Next.js.
*
* Note: the page routers proxy doesn't support streaming responses.
*
* @param request the Next API request object.
* @param response the Next API response object.
* @returns a promise that resolves when the request is handled.
*
* @deprecated Use `createPageRouterHandler` instead.
*/
export declare const handler: NextApiHandler;
type RouteHandler = (request: NextRequest) => Promise<Response>;
/**
* Creates a route handler that proxies requests to the fal API.
*
* This is a drop-in handler for Next.js applications so that the client can be called
* directly from the client-side code while keeping API keys safe.
*
* Note: you should protect this route with your application's authentication mechanism
* otherwise your proxy might be vulnerable to unauthorized access.
*
* @param config the proxy options.
* @returns a Next.js route handler function.
*/
export declare const createRouteHandler: (config?: Partial<ProxyConfig>) => {
GET: (request: NextRequest) => Promise<Response>;
POST: (request: NextRequest) => Promise<Response>;
PUT: (request: NextRequest) => Promise<Response>;
};
/**
* @deprecated Use `createRouteHandler` instead.
*/
export declare const route: {
readonly GET: RouteHandler;
readonly POST: RouteHandler;
readonly PUT: RouteHandler;
};
export {};