-
-
Save revant/4baf8c4dadc9b6b28ff3d85bd049c066 to your computer and use it in GitHub Desktop.
location / { | |
rewrite ^(.+)/$ $1 permanent; | |
rewrite ^(.+)/index\.html$ $1 permanent; | |
rewrite ^(.+)\.html$ $1 permanent; | |
# Allow CORS for static files | |
add_header Access-Control-Allow-Origin $cors_origin; | |
add_header Access-Control-Allow-Methods "GET, OPTIONS"; | |
location ~* ^/files/.*.(htm|html|svg|xml) { | |
add_header Content-disposition "attachment"; | |
# Allow CORS again, specifically for the above filetypes | |
add_header Access-Control-Allow-Origin $cors_origin; | |
add_header Access-Control-Allow-Methods "GET, OPTIONS"; | |
try_files /$site_name/public/$uri @webserver; | |
} | |
try_files /$site_name/public/$uri @webserver; | |
} |
location @webserver { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
if ($request_method = 'POST') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
} | |
if ($request_method = 'GET') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
} | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Frappe-Site-Name site1.local.com; | |
proxy_set_header Host $host; | |
proxy_set_header X-Use-X-Accel-Redirect True; | |
proxy_read_timeout 120; | |
proxy_redirect off; | |
proxy_pass http://frappe-bench-frappe; | |
} |
Hi Revant,
I m trying to connect to a 3rd party server using a client script.
The calls (from my ERPNEXT to the 3rd party server) get response and they are working fine "only" when I disable the Chrome security.
If I don't disable the browser security I get :
Access to fetch at 'https://*./connect/token' from origin 'https://my*.erpnext*.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I read your notes and I have your standard Docker Swarm installation (single Bench).
I noticed your mentioned "This gist is not /etc/nginx/nginx.conf, it should be part of /config/nginx.conf"
Does this means that I have to login to the frappe-bench-v13_erpnext-nginx container and add these lines or to another container?
Thanks,
General note on CORS
*
hosts is not secure)This gist is not
/etc/nginx/nginx.conf
, it should be part of<frappe-bench>/config/nginx.conf
If requests fail with CORS error in browser even after enabling CORS on backend, try to call
/api/method/version
endpoint, if that works, CORS is enabled and error is due to something else. This happens because CORS is only enabled for success responses