@fal-ai/server-proxy
Version:
The fal.ai server proxy adapter for JavaScript and TypeScript Web frameworks
34 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRouteHandler = createRouteHandler;
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 param the proxy options.
* @returns a Hono route handler function.
*/
function createRouteHandler({ resolveApiKey = index_1.resolveApiKeyFromEnv, }) {
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,
});
return response;
};
return routeHandler;
}
//# sourceMappingURL=hono.js.map