Hi all,
I am trying to send request from my local web app to my local dev Jooby server, I got some failures due to CORS policy disallowing the requests.
I tried to send requests both with axios.js or native fetch: if a preflight OPTIONS is send to the server my request will always fail saying the method is disallowed, if I only send a GET it works.
I'm running Jooby with
{
use("*", new CorsHandler());
}
I looked a little bit at the impl and it's essentially a Route filter, I didn't spent too much time on how the config is merged and that's why I have these 2 questions:
1. I tried to add OPTIONS to my dev config, but that didn't fix the preflighted requests case
# Allowed methods: Set the Access-Control-Allow-Methods header
allowedMethods: [GET, POST]
Does Jooby uses either the .conf options or the CorsHandler ones? Basically I don't understand if the handler is always required to enable CORS or if you could simply enable CORS support from the config.
Also if the handler uses the config, why is not liking my OPTIONS preflight request?
2. Is there a way to see all the currently used config values in the server through some debug handler or should I just print them out in some module?
I see on startup that the correct config is picked up from the config tree print, but I want to make sure that OPTIONS is being picked up
Thanks,
This is the code, in the failing version I set custom headers and that cause the library to do a preflight in the ok version has no custom headers
credentials: 'omit',
/*
headers: {
accept: 'text/plain',
'accept-language': 'en-US,en;q=0.9,it;q=0.8',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1'
},
*/
referrerPolicy: 'no-referrer-when-downgrade',
body: null,
method: 'GET',
mode: 'cors'
})
This is the one that fails
And response headers
HTTP/1.1 405 Method Not Allowed
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=UTF-8
content-length: 2923
connection: keep-alive
This is the one that works
Response headers
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Credentials: true
Content-Type: text/html;charset=UTF-8
content-length: 45
connection: keep-alive