Hi Jörg,
The auto_options in the router section enables the OPTION method for all registered endpoints in the gateway. It is completely unrelated to the CORS configuration. When using auto_options, the gateway does not call or involve any backend when used, as it simply returns an "allow" header with the supported methods. For instance:
$ curl -XOPTIONS -i http://localhost:8080/test
HTTP/1.1 200 OK
Allow: DELETE, GET
X-Krakend: Version 2.3.2-ee
Date: Fri, 07 Jul 2023 08:52:05 GMT
Content-Length: 0
The backend has not been called.
Now to the CORS part. When you enable the CORS middleware (I am using your configuration), if the client does not set any CORS-related headers (i.e. Origin or Access-Control-Request-Method) it keeps having the same output as before and CORS does not trigger:
$ curl -XOPTIONS -i http://localhost:8080/test
HTTP/1.1 200 OK
Allow: DELETE, GET
X-Krakend: Version 2.3.2-ee
Date: Fri, 07 Jul 2023 08:52:05 GMT
Content-Length: 0
When you pass CORS header, such as the header Access-Control-Request-Method, CORS is triggered, and you can see the Vary header added by the CORS middleware:
$ curl -H'Access-Control-Request-Method: GET' -XOPTIONS -i http://localhost:8080/test
HTTP/1.1 204 No Content
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Date: Fri, 07 Jul 2023 08:55:49 GMT
And you can see in the KrakenD logs in this case:
2023/07/07 08:57:09 KRAKEND DEBUG: [CORS] 2023/07/07 08:57:09 Handler: Preflight request
origin
missing origin
As you can see, the origin is missing in our previous test. Let's add it:
$ curl -H'Origin: http://localhost:8080' -H'Access-Control-Request-Method: GET' -XOPTIONS -i http://localhost:8080/test
HTTP/1.1 204 No Content
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: http://localhost:8080
Access-Control-Max-Age: 43200
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Date: Fri, 07 Jul 2023 08:58:04 GMT
And now you see in the KrakenD logs:
2023/07/07 08:58:25 KRAKEND DEBUG: [CORS] 2023/07/07 08:58:25 Handler: Preflight request
s: map[Access-Control-Allow-Credentials:[true] Access-Control-Allow-Methods:[GET] Access-Control-Allow-Origin:[http://localhost:8080] Access-Control-Max-Age:[43200] Vary:[Origin Access-Control-Request-Method Access-Control-Request-Headers]]
2023/07/07 08:58:25 KRAKEND DEBUG: [CORS] 2023/07/07 08:58:25 Preflight response headers: map[Access-Control-Allow-Credentials:[true] Access-Control-Allow-Methods:[GET] Access-Control-Allow-Origin:[http://localhost:8080] Access-Control-Max-Age:[43200] Vary:[Origin Access-Control-Request-Method Access-Control-Request-Headers]]
CORS is working.
I would start with an allow of ["*"] for your tests, and also for input_headers and make it more restrictive. Also, as a backend, you can use temporarily a KrakenD backend (with an echo endpoint) to discard problems with the backend integration.
From here, honestly, I don't know how I can offer more practical help, as you don't specify your testing process, what headers you are sending, and so on... If it's impossible to reproduce what you are doing, it isn't easy to help.
Your configuration is correct, the tests above are copy and paste of the config you pasted, replacing the 3000 port with 8080.
El dia dijous, 6 de juliol de 2023 a les 9:13:35 UTC+2,
jo...@woerd.org va escriure: