serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

No 'Access-Control-Allow-Origin' when sending a stringified Object in request parameter

Open samikarak opened this issue 7 years ago • 3 comments

Hello,

This error occurs on production after deploying my application via serverless. My express server is using the cors library ( app.use(cors()) at the beginning of my express application ). my http setting of my serverless.yml file are:

functions:
  webBackend:
    handler: handler.index
    events:
      - http: ANY {proxy+}
      - http: ANY /

normally sending GET requests with query parameters works fine e.g.

[my_items_route]?query=stuhlhusse

But when I send a GET query with the following request parameter : [another_get_route]?filters={%225d9b60f5d7610d408d8b751d%22:[%225d9b60f5d7610d408d8b751e%22]}

I get the following error : Failed to load [my_get_route]?filters={%225d9b60f5d7610d408d8b751d%22:[%225d9b60f5d7610d408d8b751e%22]}: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'

sending the request without the query parameters on the same route is also working normally.

I can't figure this out

versions aws-serverless-express : 3.3.6 nodejs : 8.11

samikarak avatar Oct 18 '19 10:10 samikarak

Do you have route handling for OPTIONS? The cors package only works on defined routes. If youre pre-flighting, you need to have the OPTIONS action for the route defined

nickanna42 avatar Oct 18 '19 13:10 nickanna42

I don't have setup any settings for any OPTIONS actions. There are a lot of other pre-flight requests which doesn't get blocked, just this one ...

samikarak avatar Oct 21 '19 12:10 samikarak

The requests that does not work contains a % character and the working request does not. Issue #219 may be playing a factor in why you are erroring

nickanna42 avatar Oct 21 '19 15:10 nickanna42