Remix proxy
It would be great to have a Remix proxy in the lib! I've tried to use the open branch feature/remix-proxy , but didn't manage to get it to work. Please revive and merge it for us Remix fans , Thanks!
i second this request
Cool! It's good to know there's some interest in Remix support. I'll pick it back up as soon as possible.
try this
import { handleRequest } from '@fal-ai/serverless-proxy'
import type { ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs } from '@remix-run/node'
import { json } from '@remix-run/node'
const proxy = async ({ request }: ActionFunctionArgs | LoaderFunctionArgs) => {
const responseHeaders = new Headers()
return handleRequest({
id: 'remix',
method: request.method,
respondWith: (status, data) => json(data, { status, headers: responseHeaders }),
getHeaders: () => Object.fromEntries(request.headers.entries()),
getHeader: (name) => request.headers.get(name),
sendHeader: (name, value) => responseHeaders.set(name, value),
getBody: async () => JSON.stringify(await request.json()),
})
}
export const action: ActionFunction = proxy
export const loader: LoaderFunction = proxy
We added remix-run support in the proxy v0.9.0, which was just released! See PR #82 for details.
The simplest use-case is to just re-export the proxy route handler:
api.fal.proxy.ts
import { createProxy } from "@fal-ai/serverless-proxy/remix";
import { json } from "@remix-run/node"; // or cloudflare, deno
const proxy = createProxy({
json
});
// just re-exporting, but you can create your own logic by providing you own function
// and then calling to proxy.action(req) or proxy.loader(req)
export const { action, loader } = proxy;
Then in the client-side, you can setup the client to proxy calls via your route handler:
_index.tsx
fal.config({
proxyUrl: "/api/fal/proxy",
});
Closing this issue as it's been resolved. Feel free to reach out if you have any other issues or feedback.