I have an app created with fastify, when testing the app in dev mode everything works fine but when deployed to cloud run I get error 400. This is only happening when one of parameters is too long (for example 7400 characters), the error I see is a cors error: "Access to XMLHttpRequest at 'https://myapp/resourse?id=XXX' from origin 'http://localhost:9000'has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
I tried to enable CORS with the following:
fastify.register(require('fastify-cors'), (instance) => (req, callback) => {
let corsOptions;
// do not include CORS headers for requests from localhost
if (/localhost/.test(origin)) {
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
}
callback(null, corsOptions) // callback expects two parameters: error and options
})
But this doesn't solve the problem. Any ideas why is this happening? It shouldn't be CORS error since I receive OK response with smaller parameters.