{"id":5067,"date":"2020-04-22T11:08:00","date_gmt":"2020-04-22T11:08:00","guid":{"rendered":"https:\/\/azoora.com\/blog\/?p=5067"},"modified":"2020-08-21T11:30:21","modified_gmt":"2020-08-21T11:30:21","slug":"simple-node-js-proxy","status":"publish","type":"post","link":"https:\/\/azoora.com\/blog\/code\/simple-node-js-proxy\/","title":{"rendered":"Simple Node.js Proxy"},"content":{"rendered":"\n<p>When you want to refresh your React.js skills, you can quickly move to create a dashboard of cryptocurrencies, their prices, and and other aspects of digital value. Getting rolling with React.js is a breeze &#8212;\u00a0<code>create-react-app {name}<\/code>\u00a0and you&#8217;re off and running. Getting the API working isn&#8217;t quick, especially if they don&#8217;t accept cross-origin requests.<\/p>\n\n\n\n<p>So, you set out to find the easiest possible <strong>Node.js<\/strong> proxy and you think you found it:\u00a0<code><a href=\"https:\/\/github.com\/chimurai\/http-proxy-middleware\">http-proxy-middleware<\/a><\/code>; check out how easy it was to use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ ... after `npm install express http-proxy-middleware`\n\nconst express = require('express');\nconst { createProxyMiddleware } = require('http-proxy-middleware');\n\nconst app = express();\napp.use('\/coins\/markets', createProxyMiddleware({ \n    target: 'https:\/\/api.coingecko.com\/api\/v3\/coins\/markets?vs_currency=USD&amp;order=market_cap_desc&amp;per_page=100&amp;page=1&amp;sparkline=false',\n    headers: {\n        accept: \"application\/json\",\n        method: \"GET\",\n    },\n    changeOrigin: true\n}));\napp.listen(3001);<\/pre>\n\n\n\n<p>After\u00a0<code>node server.js<\/code>\u00a0is executed, you can hit <code>http:\/\/localhost:3001\/coins\/markets<\/code> from my <strong>React app<\/strong> and receive quotes from <strong>CoinGecko&#8217;s API<\/strong>. Perfect!<\/p>\n\n\n\n<p>We&#8217;re so grateful for projects like\u00a0<code><a href=\"https:\/\/github.com\/chimurai\/http-proxy-middleware\">http-proxy-middleware<\/a><\/code>\u00a0; they allow us to easily move past development issues and help us move forward!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you want to refresh your React.js skills, you can quickly move to create a dashboard of cryptocurrencies, their prices, and and other aspects of digital value. Getting rolling with React.js is a breeze &#8212;\u00a0create-react-app {name}\u00a0and you&#8217;re off and running. Getting the API working isn&#8217;t quick, especially if they don&#8217;t accept cross-origin requests. So, you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":3184,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[4,145,12],"tags":[25,146,87,166,217],"jetpack_featured_media_url":"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2019\/11\/NodeJs.png","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p7FQPL-1jJ","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5067"}],"collection":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/comments?post=5067"}],"version-history":[{"count":1,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5067\/revisions"}],"predecessor-version":[{"id":5068,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5067\/revisions\/5068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media\/3184"}],"wp:attachment":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media?parent=5067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/categories?post=5067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/tags?post=5067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}