{"id":7819,"date":"2020-01-09T21:21:07","date_gmt":"2020-01-09T21:21:07","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=7819"},"modified":"2020-01-09T21:21:07","modified_gmt":"2020-01-09T21:21:07","slug":"express-server-and-cors","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/express-server-and-cors\/","title":{"rendered":"Express server and cors"},"content":{"rendered":"<p>If we need to handle CORS within Express, we can simply write the following (we&#8217;ll assume you&#8217;ve also added express to your packages)<\/p>\n<ul>\n<li>yarn add cors<\/li>\n<\/ul>\n<p>Now our usual Express code with the addition of CORS support<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport express from &quot;express&quot;;\r\nimport cors from &quot;cors&quot;;\r\n\r\nconst app = express();\r\nconst server = http.createServer(app);\r\n\r\napp.use(cors());\r\n\r\nconst port = 4000;\r\nserver.listen(port, \r\n  () =&gt; console.log(`Server on port ${port}`)\r\n);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If we need to handle CORS within Express, we can simply write the following (we&#8217;ll assume you&#8217;ve also added express to your packages) yarn add cors Now our usual Express code with the addition of CORS support import express from &quot;express&quot;; import cors from &quot;cors&quot;; const app = express(); const server = http.createServer(app); app.use(cors()); const [&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-7819","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\/7819","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=7819"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7819\/revisions"}],"predecessor-version":[{"id":7845,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/7819\/revisions\/7845"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=7819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=7819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=7819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}