@fal-ai/server-proxy
Version:
The fal.ai server proxy adapter for JavaScript and TypeScript Web frameworks
36 lines • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRouteHandler = createRouteHandler;
const config_1 = require("./config");
const index_1 = require("./index");
/**
* Creates a route handler that proxies requests to the fal API.
*
* This is a drop-in handler for Hono applications so that the client can be called
* directly from the client-side code while keeping API keys safe.
*
* @param config the proxy configuration options.
* @returns a Hono route handler function.
*/
function createRouteHandler({ resolveApiKey = index_1.resolveApiKeyFromEnv, ...config } = {}) {
const resolvedConfig = (0, config_1.resolveProxyConfig)(config);
const routeHandler = async (context) => {
const responseHeaders = {};
const response = await (0, index_1.handleRequest)({
id: "hono",
method: context.req.method,
respondWith: (status, data) => {
return context.json(data, status, responseHeaders);
},
getHeaders: () => responseHeaders,
getHeader: (name) => context.req.header(name),
sendHeader: (name, value) => (responseHeaders[name] = value),
getRequestBody: async () => JSON.stringify(await context.req.json()),
sendResponse: index_1.responsePassthrough,
resolveApiKey,
}, resolvedConfig);
return response;
};
return routeHandler;
}
//# sourceMappingURL=hono.js.map