From 76f9b46e7c3154816033c506bfe818b3f51b6657 Mon Sep 17 00:00:00 2001 From: SchulzeStTSI <67590336+SchulzeStTSI@users.noreply.github.com> Date: Fri, 10 Dec 2021 17:49:16 +0100 Subject: [PATCH] Cors Enable --- nginx/default.conf.template | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nginx/default.conf.template b/nginx/default.conf.template index 5a496b1..3e35641 100644 --- a/nginx/default.conf.template +++ b/nginx/default.conf.template @@ -2,6 +2,34 @@ server { listen 80; server_name localhost; location / { + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + # + # Tell client that this pre-flight info is valid for 20 days + # + 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' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + } + proxy_pass http://localhost:8080/identity; } location /identity {