Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix proxy #58

Closed
amitrab opened this issue Mar 8, 2024 · 5 comments
Closed

Remix proxy #58

amitrab opened this issue Mar 8, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@amitrab
Copy link

amitrab commented Mar 8, 2024

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!

@agawrylak
Copy link

i second this request

@drochetti
Copy link
Collaborator

Cool! It's good to know there's some interest in Remix support. I'll pick it back up as soon as possible.

@nicknikolov
Copy link

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

@drochetti drochetti added the enhancement New feature or request label Aug 7, 2024
@drochetti
Copy link
Collaborator

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",
});

@drochetti
Copy link
Collaborator

Closing this issue as it's been resolved. Feel free to reach out if you have any other issues or feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants