{"id":3428,"date":"2020-02-17T22:58:19","date_gmt":"2020-02-17T21:58:19","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3428"},"modified":"2020-02-19T00:26:24","modified_gmt":"2020-02-18T23:26:24","slug":"nginx-enable-cors","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/nginx-enable-cors\/","title":{"rendered":"Nginx enable CORS"},"content":{"rendered":"\n<p><a href=\"https:\/\/gist.github.com\/Stanback\/7145487\">https:\/\/gist.github.com\/Stanback\/7145487<\/a><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\n# CORS config for nginx\n#\n\nlocation \/cors {\n        add_header 'Access-Control-Allow-Origin' \"$http_origin\" always;\n        add_header 'Access-Control-Allow-Credentials' 'true' always;\n        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;\n        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;\n        # required to be able to read Authorization header in frontend\n        #add_header 'Access-Control-Expose-Headers' 'Authorization' always;\n\n        if ($request_method = 'OPTIONS') {\n                # Tell client that this pre-flight info is valid for 20 days\n                add_header 'Access-Control-Max-Age' 1728000;\n                add_header 'Content-Type' 'text\/plain charset=UTF-8';\n                add_header 'Content-Length' 0;\n                return 204;\n        }\n}<\/pre>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fetch(\"https:\/\/solidt.eu\/data\/example_2.json\").then(x => x.json()).then(x => console.log(x))<\/pre>\n\n\n\n<p><a href=\"https:\/\/enable-cors.org\/server_apache.html\">https:\/\/enable-cors.org\/server_apache.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/gist.github.com\/Stanback\/7145487 Example: https:\/\/enable-cors.org\/server_apache.html<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3428","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3428"}],"version-history":[{"count":4,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3428\/revisions"}],"predecessor-version":[{"id":3450,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3428\/revisions\/3450"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}