-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
How to deal with OPTIONS requests in BFF? #5093
Comments
Was about to post this in the original discussion but just seen this issue pop up 😄. For context this doesn't break anything directly in our app currently but was an interesting find in our logs this afternoon - happened upon the original discussion while doing some digging. We're seeing this same error on Vercel preview deployments - the scripts for their new Comments feature that get injected into the page make an OPTIONS request to the current origin on startup: This returns a 405 response with a similar stack trace as in @ligiaandreica's original post:
This points to the following The Vercel script seems to fail gracefully and so doesn't tank the rest of the page, but adding the info to this issue as it looks like this might have some impact beyond Remix BFF usage. The error was originally found on a Remix v1.8.2 app - I've created a minimal reproduction of what the Vercel script is doing here with the latest version of Remix (v1.10.0), which throws the same error: https://github.com/ezg27/remix-options-error-repro |
Confirming the issue with the Vercel widget, but I think the problem originates here: https://github.com/remix-run/react-router/blob/main/packages/router/router.ts#L2073 |
While we don't have this issue in our production environment due to an API gateway, locally we also have this issue. This works for our use case: if (process.env.NODE_ENV === 'development') {
app.options('/api/*', cors());
} |
This should be available in |
Released in 1.11.0 |
Thank you for the quick fix. 🎉 It's working fine for client -> BFF use case. |
I am still facing this issue even though I enabled cors: export const loader = async ({ request }: LoaderFunctionArgs) => {
const { session, admin } = await authenticate.admin(request);
// explicitly handle options
if (request.method === "OPTIONS") {
return await cors(request, json(null));
}
// Some logic
return await cors(request, json(someData));
}; I get an exception in the router package when I receive a request:
|
Same for me. I'm still getting this error. Any fix ? |
@muco-rolle This issue was closed two years ago. Please submit a new one providing all the information needed to reproduce it. |
Discussed in #5067
Originally posted by ligiaandreica January 11, 2023
I am using remix as BFF, implementation based on docs.
The client
(on a different domain) callsBFF
to get some data and then the requests go todownstream APIs
. Basically, it's the preflight OPTIONS request to verify the client can do the GET.This was working fine with some
remix-utils
cors
setup untilv1.8.0
of remix.Started getting
Error: Invalid request method "OPTIONS"
once I've upgraded fromv1.7.6
. This error seems expected according to the release docs.Am I missing some configuration or is this a new limitation?
@jacob-ebey or @brophdawg11 could you please advise as this is part of #4385?
The text was updated successfully, but these errors were encountered: