UNPKG

@fal-ai/serverless-proxy

Version:

Deprecation note: this library has been deprecated in favor of @fal-ai/server-proxy

43 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRequestHandler = void 0; const index_1 = require("./index"); /** * Creates the SvelteKit request handler for the fal.ai client proxy on App Router apps. * The passed credentials will be used to authenticate the request, if not provided the * environment variable `FAL_KEY` will be used. * * @param params the request handler parameters. * @returns the SvelteKit request handler. */ const createRequestHandler = ({ credentials, } = {}) => { const handler = async ({ request }) => { const FAL_KEY = credentials || process.env.FAL_KEY || ""; // eslint-disable-next-line @typescript-eslint/no-explicit-any const responseHeaders = { "Content-Type": "application/json", }; return await (0, index_1.handleRequest)({ id: "svelte-app-router", method: request.method, getRequestBody: async () => request.text(), getHeaders: () => (0, index_1.fromHeaders)(request.headers), getHeader: (name) => request.headers.get(name), sendHeader: (name, value) => (responseHeaders[name] = value), resolveApiKey: () => Promise.resolve(FAL_KEY), respondWith: (status, data) => new Response(JSON.stringify(data), { status, headers: responseHeaders, }), sendResponse: index_1.responsePassthrough, }); }; return { requestHandler: handler, GET: handler, POST: handler, PUT: handler, }; }; exports.createRequestHandler = createRequestHandler; //# sourceMappingURL=svelte.js.map