{"id":7489,"date":"2022-10-11T20:47:11","date_gmt":"2022-10-11T20:47:11","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=7489"},"modified":"2022-10-11T20:47:11","modified_gmt":"2022-10-11T20:47:11","slug":"cors-and-expressjs","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/cors-and-expressjs\/","title":{"rendered":"Cors and expressjs"},"content":{"rendered":"<p><em>Note: This post was written a while back but sat in draft. I&#8217;ve published this now, but I&#8217;m not sure it&#8217;s relevant to the latest versions etc. so please bear this in mind.<\/em><\/p>\n<p>This is a simple reminder post for myself, please see <a href=\"https:\/\/expressjs.com\/en\/resources\/middleware\/cors.html\" rel=\"noopener\" target=\"_blank\">cors<\/a> for complete documentation.<\/p>\n<p>To enable CORS within expressjs, add the package<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nyarn add cors\r\n<\/pre>\n<p>The import using<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport cors from &quot;cors&quot;;\r\n<\/pre>\n<p>and now to use cors within the middleware we use<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nvar server = express()\r\n\r\nserver.use(cors());\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Note: This post was written a while back but sat in draft. I&#8217;ve published this now, but I&#8217;m not sure it&#8217;s relevant to the latest versions etc. so please bear this in mind. This is a simple reminder post for myself, please see cors for complete documentation. To enable CORS within expressjs, add the package [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[268],"tags":[],"class_list":["post-7489","post","type-post","status-publish","format-standard","hentry","category-express"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=7489"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7489\/revisions"}],"predecessor-version":[{"id":9586,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7489\/revisions\/9586"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=7489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=7489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=7489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}