Error: Invalid request method "OPTIONS"

Hi,
When testing our code locally, it looks like our browser (and Postman) is able to make an OPTIONS call to verify our CORS data.

Our APIs (on Remix, using routes + loaders for routes) has this code
if (request.method === ‘OPTIONS’) {
return new Response(null, {
headers: {
‘Access-Control-Allow-Origin’: ‘’,
‘Access-Control-Allow-Methods’: ‘PUT, POST, GET, DELETE, OPTIONS’,
‘Access-Control-Allow-Headers’: ‘’,
‘Access-Control-Max-Age’: ‘9999999’,
},
});
}
Things are good locally.

However, after deploying on our server, I see this in our fly.io app logs.
ErrorResponse {
status: 405,
statusText: ‘Method Not Allowed’,
internal: true,
data: ‘Error: Invalid request method “OPTIONS”’,
error: Error: Invalid request method “OPTIONS”
at getInternalRouterError (/myapp/node_modules/@remix-run/router/router.ts:3072:5)
at Object.queryRoute (/myapp/node_modules/@remix-run/router/router.ts:2055:13)
at handleResourceRequestRR (/myapp/node_modules/@remix-run/server-runtime/dist/server.js:271:40)
at requestHandler (/myapp/node_modules/@remix-run/server-runtime/dist/server.js:47:24)
at /myapp/node_modules/@sentry/src/utils/instrumentServer.ts:432:1
at bound (node:domain:433:15)
at runBound (node:domain:444:12)
at /myapp/node_modules/@sentry/src/utils/instrumentServer.ts:438:1
at /myapp/node_modules/@remix-run/express/dist/server.js:39:28
at Layer.handle [as handle_request] (/myapp/node_modules/express/lib/router/layer.js:95:5)

Postman returns 500 Internal Server Error

Thoughts on whether this is a config setting? Appreciate your help.

Hi!

Fly’s proxy layer doesn’t block/change/care about OPTIONS vs other standard HTTP verbs so from that perspective, it should work.

That stack trace does looks like it was hitting your code base so in theory if there was Nginx or something running in your VM, that also doesn’t appear to be getting in the way.

Is there anything else in between you and your Fly app? Perhaps a proxy that might change the URL the code base sees? (I’m not super familiar with remix and how it does routing).

Thanks for responding. There is nothing between my Postman and Fly. It looks like the GET request comes through, but since the APIs are hosted (as resource routes) in fly, another host is unable to access them (as the OPTIONS call is not coming through - OPTIONS allow Access-Control-Allow-Origin).

Option calls don’t seem to make it to our route.