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

Didn't Return CORS from OPTIONS method

Open rroqueCoddera opened this issue 10 years ago • 10 comments

I'm calling a method POST that has a OPTIONS method together and cors from a OPTIONS method returns wrong.

That's my configuration on serverless.yml:

functions: load: handler: handler.main events: - http: path: /load method: POST cors: true - http: path: /load method: OPTIONS cors: true

Return:

Request URL:http://localhost:3000/load Request Method:OPTIONS Status Code:200 OK Remote Address:127.0.0.1:3000

Response Header access-control-allow-credentials:true access-control-allow-origin:null access-control-expose-headers:WWW-Authenticate,Server-Authorization cache-control:no-cache Connection:keep-alive content-encoding:gzip content-type:application/json; charset=utf-8 Date:Fri, 02 Sep 2016 14:47:32 GMT Transfer-Encoding:chunked vary:origin,accept-encoding

I'm making the request from a web page, because with postman works fine.

is it a bug?

rroqueCoddera avatar Sep 02 '16 14:09 rroqueCoddera

Not certain. Can you explain further. You did a POST and it used OPTIONS verb instead?

Bilal-S avatar Sep 02 '16 18:09 Bilal-S

When I call a POST method from a webPage, it is first calls a OPTIONS method to check CORS, and them calls the POST method.

https://www.w3.org/TR/cors/

rroqueCoddera avatar Sep 03 '16 13:09 rroqueCoddera

Ok. I will check. The goal is to only invoke POST in that scenario, correct?

Bilal-S avatar Sep 06 '16 01:09 Bilal-S

No, browser will send OPTIONS before a POST, so we have to treat correctly CORS on OPTIONS method.

rroqueCoddera avatar Sep 06 '16 22:09 rroqueCoddera

@Bilal-S Hi Bilal, I see a lot of new issues but I don't have time to solve them all. You seem to be doing a pretty good job around them, do you need any kind of assistance?

dherault avatar Sep 07 '16 07:09 dherault

@dherault I am pretty slammed this week. I have put aside some time next week to look at the issues and was hoping to also refactor some code. The RC1 release has breaking changes so I need to check that out as well.

Bilal-S avatar Sep 07 '16 21:09 Bilal-S

@Bilal-S Yeah I'm slammed too... Thanks a lot, it's ok if you can't.

dherault avatar Sep 12 '16 15:09 dherault

so we have to treat correctly CORS on OPTIONS method.

@Bilal-S Is it fixed? If not I'll do it. I feel the v1 comming :)

dherault avatar Oct 09 '16 20:10 dherault

@dherault not fixed yet afaik. Would be cool if you could take a look.

Bilal-S avatar Oct 09 '16 21:10 Bilal-S

Fixed in v3.3.3, thanks @mhodgson

dherault avatar Nov 20 '16 08:11 dherault