{"id":2250,"date":"2022-05-13T09:51:16","date_gmt":"2022-05-13T13:51:16","guid":{"rendered":"https:\/\/shirishranjit.com\/blog1\/?page_id=2250"},"modified":"2022-05-13T09:51:55","modified_gmt":"2022-05-13T13:51:55","slug":"cors-header-access-control-allow-origin-missing-primer","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/reactjs\/building-ui-with-reactjs\/cors-header-access-control-allow-origin-missing-primer","title":{"rendered":"CORS header &#8216;Access-Control-Allow-Origin&#8217; missing\u00a0&#8211; Primer"},"content":{"rendered":"\n<p>CORS setting is necessary if you have traffic coming from different domain. This is one of the security that you can put for disallow connection. However, you have need for allowing various domain to be able to access your service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule mod_headers.c>\n    SetEnvIf Origin \"http(s)?:\/\/(www\\.)?(domain1.org|domain2.com|domain3.net)$\" AccessControlAllowOrigin=$0$1\n    Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin\n    Header set Access-Control-Allow-Credentials true\n&lt;\/IfModule><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SetEnvIf Origin \"^http(s)?:\/\/(.+\\.)?(domain\\.org|domain2\\.com)$\" origin_is=$0 \nHeader always set Access-Control-Allow-Origin %{origin_is}e env=origin_is<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable cross domain access control\nSetEnvIf Origin \"^http(s)?:\/\/(.+\\.)?(domain1\\.com|domain2\\.org|domain3\\.net)$\" REQUEST_ORIGIN=$0\nHeader always set Access-Control-Allow-Origin %{REQUEST_ORIGIN}e env=REQUEST_ORIGIN\nHeader always set Access-Control-Allow-Methods \"GET, POST, PUT, DELETE, OPTIONS\"\nHeader always set Access-Control-Allow-Headers \"x-test-header, Origin, X-Requested-With, Content-Type, Accept\"\n\n# Force to request 200 for options\nRewriteEngine On\nRewriteCond %{REQUEST_METHOD} OPTIONS\nRewriteRule .* \/ &#91;R=200,L]\n\n<\/code><\/pre>\n\n\n\n<p>References:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CORS\/Errors\/CORSMissingAllowOrigin\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CORS\/Errors\/CORSMissingAllowOrigin<\/a><\/li><li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CORS\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CORS<\/a><\/li><li><a href=\"https:\/\/enable-cors.org\/server_apache.html\">https:\/\/enable-cors.org\/server_apache.html<\/a><\/li><\/ul>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=CORS+header+%27Access-Control-Allow-Origin%27+missing%C2%A0-+Primer\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/reactjs\/building-ui-with-reactjs\/cors-header-access-control-allow-origin-missing-primer\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>CORS setting is necessary if you have traffic coming from different domain. This is one of the security that you can put for disallow connection. However, you have need for allowing various domain to be able to access your service. &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/reactjs\/building-ui-with-reactjs\/cors-header-access-control-allow-origin-missing-primer\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":1184,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2250","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2250"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=2250"}],"version-history":[{"count":2,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2250\/revisions"}],"predecessor-version":[{"id":2252,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2250\/revisions\/2252"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/1184"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=2250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}