0

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.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
shane_00
  • 101
  • 1
  • 2
  • 9
  • the maximum payload I think is 16Kb with all the headers, this is at least documented for Balancers https://cloud.google.com/load-balancing/docs/quotas#https-lb-header-limits – Pentium10 Oct 28 '21 at 12:57
  • Adding to the previous comment, there might be some configurations setting the maximum parameter size to a certain limit. You can check [this answer](https://stackoverflow.com/a/48230425/7757976) for a reference. – llompalles Nov 03 '21 at 10:54

0 Answers0