-
Notifications
You must be signed in to change notification settings - Fork 71
Duplicate CORS headers for POST requests #53
Comments
my guess is the conf file was created before postgrest started replying with those headers, i'll look into it, maybe indeed this file needs removing. on a side note, you really really want to avoid those headers in the first place (both in dev and production, each situation has different solutions). |
Thanks for the pointer - this is pretty helpful for the admin backend use case. If you think of situations, where you want to open up your API to web apps on different domains (e.g. web service usage, maybe anonymous role only), you would like to have proper CORS headers. |
I see this was addressed in a recent commit, but I still get this error when using fetch() to make a POST request to my project ( https://mggg-states.subzero.cloud ) from localhost or any other domain outside of subzero.cloud - any advice? |
Previously done in 7f11591 and reference: subzerocloud/postgrest-starter-kit#53
Communication with the REST API for POST requests will put duplicated CORS (Access-Control-*) headers into any response.
When using the REST API endpoints from a JS app in a browser (I used react-admin as a sample), this behavoiur leads to the following error in a browser console:
Test case with RPC login endpoint (same behaviour for resources):
Example output:
openresty/nginx/conf/includes/http/server/locations/rest/cors.conf
(line 12-19)src/PostgREST/Config.hs
(line 89-105)IMHO the current
cors.conf
is not needed at all, as PostgREST will always add CORS headers on its own, (also for OPTIONS requests).My fix was to comment / delete everything inside
openresty/nginx/conf/includes/http/server/locations/rest/cors.conf
, which makes everything work perfectly.The only use case where these headers might be needed, is when using the
subzero.jwt_session_cookie
module (with subzero-starter-kit) as this module will not add the headers itself.Maybe I'm overlooking something additional, which might still be dependent on the LUA injection of these headers (you put them there for a reason I guess). A better options to fix it might be to only add these headers by LUA in a response hook, if they're not already there in the response.
The text was updated successfully, but these errors were encountered: