<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pranav Shikarpur on Medium]]></title>
        <description><![CDATA[Stories by Pranav Shikarpur on Medium]]></description>
        <link>https://medium.com/@pranav.shikarpur?source=rss-5f5fe931997d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*J-ntC0MQlIvtKJD1WRsUyw.jpeg</url>
            <title>Stories by Pranav Shikarpur on Medium</title>
            <link>https://medium.com/@pranav.shikarpur?source=rss-5f5fe931997d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:31:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pranav.shikarpur/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Key Managers  — How Do I Pick the Right One for My Org?!]]></title>
            <link>https://medium.com/@pranav.shikarpur/key-managers-how-do-i-pick-the-right-one-for-my-org-cd2ce4362929?source=rss-5f5fe931997d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd2ce4362929</guid>
            <category><![CDATA[key-management]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Pranav Shikarpur]]></dc:creator>
            <pubDate>Sun, 27 Nov 2022 00:03:37 GMT</pubDate>
            <atom:updated>2022-11-27T00:03:37.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*eu7t414dsTqX4d5sCjEkgA.png" /><figcaption>Cryptographic Key Illustration (Source — generated using Stable Diffusion on playgroundai.com)</figcaption></figure><h3>Key Managers 🔐 — How Do I Pick the Right One for My Org?!</h3><p>Your company has a ton of daily active users and you have this amazingly efficient architecture to process requests at scale, but your InfoSec team asks you to use a key manager — there are so many out there, which one do you choose?</p><p>There are various different types of key managers, but in this post, we’ll cover the three most common key managers:</p><ul><li>Native Cloud Key Managers (Ex — AWS KMS, GCP KMS, Azure Key Vault, etc.)</li><li>External Key Managers (Ex — Thales CipherTrust Manager, etc.)</li><li>Hybrid Key Managers (Use the best of both worlds — Cloud managed services and external key managers)</li></ul><h3>First, the literal key to security — HSMs</h3><p>HSM stands for “<a href="https://en.wikipedia.org/wiki/Hardware_security_module">Hardware Security Module</a>”. These are physical devices that are usually tamper resistant which store keys and perform encrypt, decrypt and other cryptographic operations.</p><p>HSMs are needed in secure environments such as healthcare or financial institutions where you need to pass compliances such as PCI DSS.</p><h3>Now Let’s Compare</h3><p>Let’s look at the pros and cons of each to help you decide what would work best for your organization.</p><h4>Cloud Key Managers</h4><p>✅ <strong>Easy Integration with Cloud Managed Services</strong></p><p>When using cloud key managers like <a href="https://aws.amazon.com/kms/">AWS KMS (Key Management Service)</a> it can be advantageous as you get the flexibility of AWS managing your keys as well as direct integration into your existing AWS managed services such as <a href="https://aws.amazon.com/s3/">AWS S3</a>, or <a href="https://aws.amazon.com/rods/">AWS RDS (Relational Database Service)</a>, etc.</p><p>✅ <strong>HSMs provisioned and managed by a cloud provider (most of the time 🤞)</strong></p><p>Most famous cloud providers have HSMs that they use in their data centers which store your keys, so you don’t have to worry about renting an HSM.</p><p><strong>❌ No Separation of Trust 🕵️‍♀️</strong></p><p>Since your cloud provider now hosts and controls your data and encryption keys. Your user data might not be as safe anymore as the cloud provider with malicious intent could easily decrypt your user data. This does not help in creating a <strong>zero-trust architecture</strong>. While it’s true that your cloud provider has your best interest; there are always hackers lurking around the internet trying to get malicious access to your data, so it’s best to store data in an isolated environment.</p><h4><strong>External Key Managers</strong></h4><p><strong>✅ Complete Separation of Trust</strong></p><p>When running a product such as CipherTrust Manager or Hashicorp Vault, your architectures are zero-trust by default as 2 different entities have access to either your data or your keys and <strong>NOT both</strong>.</p><p><strong>❌ Build your own custom integrations</strong></p><p>Unless the key manager service has connectors, many a times, you would need to build your own connectors which could put a lot of engineering debt on your teams.</p><p>⚠️<strong> Need to rent out your own HSM</strong></p><p>You’d need to manage your own HSM, but fortunately, there are service providers that will rent out and manage the HSMs (just like a cloud provider) — so this is neither a pro nor a con. A great example of a hosted HSM is the <a href="https://cpl.thalesgroup.com/encryption/data-protection-on-demand/services/luna-cloud-hsm">Luna HSM</a>.</p><h3>Best of Both Worlds 🤔</h3><p>Yes, it’s possible! To implement the best data security practices, you would want the ease of integration with cloud-managed services as well as complete separation of trust to isolate encryption keys from data. This method is also called <strong>BYOK </strong>(bring your own key).</p><p>You can do this with products such as CipherTrust Manager <a href="https://cpl.thalesgroup.com/encryption/key-management/ciphertrust-cloud-key-manager">Cloud Key Manager</a>. This offers:</p><p><strong>✅ Direct connection with cloud-managed KMS account</strong></p><p>Once you connect your AWS or GCP or Azure account to CipherTrust Manager as shown in the tutorial linked below, you will be able to manage keys directly from CipherTrust Manager and encrypt data on cloud-managed services.</p><p><strong>✅ Key Lifecycle Management in a few clicks</strong></p><p>In just a few clicks you can setup key rotation which will rotate your keys every few months and provide the best data security standards for your organization.</p><h4>How do I implement this?</h4><p>Luckily, it’s easy to implement in 3 simple steps. Here’s a tutorial I made that demos connecting CipherTrust Manager to my AWS KMS (Key Management Service) account and encrypt my AWS managed services such as S3 and RDS.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9Cs9s7DpJFU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9Cs9s7DpJFU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9Cs9s7DpJFU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/36f7911a4dd774d71e26084249adfa9b/href">https://medium.com/media/36f7911a4dd774d71e26084249adfa9b/href</a></iframe><p>Now go ahead and encrypt all your cloud-managed services using this hybrid BYOK approach!</p><p>If you have any issues with implementation or questions about data encryption, feel free to leave a comment, tweet <a href="https://twitter.com/snpranav">@snpranav</a>, or raise a <a href="https://github.com/snpranav/data-encryption-in-transit-demo/issues/new">GitHub issue</a> :)</p><p>Check out our other <a href="https://thalesgroup.github.io/ciphertrust/docs/intro">tutorials to get started</a> with Thales CipherTrust Manager.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd2ce4362929" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Data Security Architectures — Encryption at Rest and in-Transit]]></title>
            <link>https://medium.com/@pranav.shikarpur/a-guide-to-data-security-architectures-encryption-at-rest-and-in-transit-ecdfb237869a?source=rss-5f5fe931997d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecdfb237869a</guid>
            <category><![CDATA[data-security]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Pranav Shikarpur]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 18:13:16 GMT</pubDate>
            <atom:updated>2022-11-14T21:36:35.899Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Guide to Data Security Architectures — Encryption at Rest and in-Transit</h3><p>Building and deploying applications and services is super exciting. Still, when your security team prevents your application from going into production due to a lack of data encryption — this can be very annoying.</p><p>Let’s take a look at the different data encryption methods that are most commonly used and how we can implement some of them.</p><h3>Data encrypted at-rest vs in-transit?</h3><p>Well, it’s often hard to choose between encrypting a complete Postgres database or encrypting only specific fields of data in the database right before it gets written to a table.</p><p>The key difference between the two is that encrypting a database <strong>after</strong> data is written to it is called <strong>data encryption at rest</strong> and encrypting data <strong>before</strong> data is written to a database is called data encryption <strong>in-transit</strong>.</p><p>The illustration below should give you a good high-level understanding of the difference. Although data encryption at-rest was a standard encryption practice followed for many years, it involves developers writing and maintaining various different scripts or applications to ensure that the encryption is up to company standards. It is still useful while encrypting file systems and storage. On the other hand, data encryption in-transit is a lot more beneficial at times when you want to make your infrastructure database agnostic and provide high-security standards with significantly low developer effort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sOyc7n62Mxsq0cfKsLL0Q.png" /><figcaption>Encrypting data at rest architecture diagram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PC9Nv4j_L2LIoWsR4ZIeg.png" /><figcaption>Encrypting data in-transit architecture diagram</figcaption></figure><p>Note that from the above diagram we can see that the method of encrypting data in-transit uses a <strong>side-car container</strong> which is a proxy used to intercept every request with sensitive fields or encrypted data and encrypt or decrypt the same respectively.</p><h4>Advantages of Data Encryption in-Transit</h4><p><strong>✅ No change to applications</strong></p><p>The beauty of doing data-encryption in transit is that you don’t need to worry about changing any of your frontend apps, APIs, or databases. Since the side-car container does field-level encryption, you can granularly control all the data that needs to be encrypted and decrypted by remotely setting access policies from your key manager.</p><p><strong>✅ Easy to deploy</strong></p><p>Deploying a <a href="https://cpl.thalesgroup.com/encryption/ciphertrust-data-protection-gateway">Data Protection Gateway</a> side-car container is as easy to deploy as logging agents such as DataDog or Prometheus. You can just update your docker-compose, Kubernetes config files or just use Helm to install it.</p><p><strong>✅ Developers can stop implementing data security policies</strong></p><p>Now you can shift the responsibility of setting and implementing data security policies from developers over to InfoSec teams. This significantly helps prevent data breaches or unauthorized data access.</p><h4>Disadvantages of Data Encryption in-Transit</h4><p>❌ <strong>Data encryption is only as strong as policies set</strong></p><p>This applies to any method of data encryption. However, when we perform field-level encryption and decryption, InfoSec teams need to be aware of all data flowing through various API routes to prevent data breaches and unauthorized access to unencrypted data.</p><h4>How Do I Implement Data Encryption in-Transit?</h4><p>You’re in luck 🙌 because I have a tutorial showing you how to easily implement data encryption in-transit with any of your containerized applications.</p><p>In this tutorial, I have used <a href="https://ciphertrust.io/">CipherTrust Manager</a>’s Data Protection Gateway product which is extremely easy to set up and free to start using👇</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEJun5McPRGY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEJun5McPRGY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEJun5McPRGY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bfac41e0db15cb216c32c555d5d72bf/href">https://medium.com/media/6bfac41e0db15cb216c32c555d5d72bf/href</a></iframe><p><a href="https://github.com/snpranav/data-encryption-in-transit-demo">GitHub - snpranav/data-encryption-in-transit-demo: This demo shows how you can encrypt data in transit by using a data protection gateway side car container.</a></p><p>Now go ahead and encrypt data in-transit from all your applications using side-car containers.</p><p>If you have any issues with implementation or questions about data encryption in-transit, feel free to leave a comment, tweet <a href="https://twitter.com/snpranav">@snpranav</a>, or raise a <a href="https://github.com/snpranav/data-encryption-in-transit-demo/issues/new">GitHub issue</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecdfb237869a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Ghost Blog in a Subdirecotory over SSL on NGINX]]></title>
            <link>https://medium.com/tech-to-startup-to-life-by-pranav/ghost-blog-in-a-subdirecotory-over-ssl-4cd200e02524?source=rss-5f5fe931997d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cd200e02524</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[ghost-blog]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Pranav Shikarpur]]></dc:creator>
            <pubDate>Sat, 02 Mar 2019 15:44:23 GMT</pubDate>
            <atom:updated>2019-03-02T16:10:39.426Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5nHNS9uAFuDhIUB0AADXw.png" /><figcaption>Cover Image</figcaption></figure><p>Have you ever wanted to start a blog with your own domain (without the classic outdated WordPress :P)? Ghost Blog is the best publishing platform to use!</p><h3>blog.domain.tld vs domain.tld/blog/:</h3><p>When you start a blog on a subdomain search engines like Google treat the subdomain as a separate domain which will not benefit the SEO of the main domain.</p><p>Therefore, it is better to start our blog on <strong><em>domain.tld/blog/.</em></strong></p><p>Note — Throughout this blog, I will be referring to domain.tld/subdirectory/; furthermore, subdirectory is the name of your subdirectory (example — If your URL is domain.tld/blog/, then blog is your subdirectory in this case)</p><h3>What is Ghost? (<a href="https://z.snpranav.com/blog/r/ghost">ghost.org</a>)</h3><p>Ghost is a fully open source, adaptable platform for building and running a modern online publication. They even power blogs, magazines and journalists from Zappos to Sky News.</p><p><strong>Note — <em>Ghost has a paid package where they host your blog, but for this tutorial, we will be using the open source </em></strong><a href="https://docs.ghost.org/"><strong><em>developer version</em></strong></a><strong><em> which can be deployed on a custom web server.</em></strong></p><p>Note — I have used Ubuntu 18.04 LTS for this tutorial. Some of the steps might differ on other operating systems.</p><p>I assume that you know how to set up an <a href="https://z.snpranav.com/blog/r/nginx">NGINX</a> web server. To follow along through this tutorial, you need to set up your NGINX web server. To learn how to set up an NGINX web server, visit — <a href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04">https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04</a></p><h3>Install SSL (<a href="https://www.digicert.com/ssl/">Secure Socket Layer</a>) certificate on web server</h3><p>Once you set up NGINX and have your main website running, install an SSL certificate. I am using <a href="https://letsencrypt.org/">Let’s Encrypt</a>; however, you can use any other SSL.</p><p>For this, I will use <a href="https://certbot.eff.org/">Certbot</a>. Run the following commands for Ubuntu 18.04 LTS:</p><pre>$ sudo apt-get update<br>$ sudo apt-get install software-properties-common<br>$ sudo add-apt-repository universe<br>$ sudo add-apt-repository ppa:certbot/certbot<br>$ sudo apt-get update<br>$ sudo apt-get install certbot python-certbot-nginx <br><br>$ sudo certbot --nginx</pre><p>Enter the domains as domain.tld (Optionally, you can also enter <a href="http://www.domain.tld)/">www.domain.tld)</a><br>Run the following command to make the certificate auto-renew</p><pre>$ sudo certbot renew --dry-run</pre><h3>How to install Ghost?</h3><p>If you are using Ubuntu 16/18, visit <a href="https://docs.ghost.org/install/ubuntu/">https://docs.ghost.org/install/ubuntu/</a>. Else, you could also use any of the alternative installation options available here <a href="https://docs.ghost.org/setup/">https://docs.ghost.org/setup/</a>.</p><p>Note — Before you run $ ghost install, make sure that you are in the subdirectory. Do not install Ghost in a new folder as mentioned in the tutorial. Install it in a SUBDIRECTORY! (To go into your subdirectory run $ cd /var/www/html/subdirecotory/)<br> When you run the $ ghost install command, remember to use the following settings:</p><ul><li>config-URL — <a href="https://domain.tld/subdirectory/">https://domain.tld/subdirectory/</a></li><li>MySQL hostname — (localhost by default)</li><li>MySQL username/password — (Enter the password as created in the ghost database creation)</li><li>Ghost database name — (Name of Database)</li><li>Setup SSL — no</li><li>Setup Systemd — yes</li><li>Start Ghost — yes</li></ul><h3>Problem with running Ghost</h3><p>Normally, webpages use port <strong>443</strong> to run over SSL (secure) connection and port <strong>80</strong> to run over a non-SSL (insecure) connection. However, Ghost runs on port <strong>2368</strong>, so we have to use a <strong>proxy </strong>that will use port 2368 when we go to the /subdirectory/ location.</p><p>For this, head over to the NGINX configuration file by running this command:</p><pre>$ cd /etc/nginx/sites-available/<br>$ nano configuration-file-name</pre><p>The configuration file should look like this by default</p><pre>server {<br><br>        root /var/www/html;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name domain.tld www.domain.tld;<br><br>        location ~ \.php$ {<br>                include snippets/fastcgi-php.conf;<br>                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;<br>        }<br><br>        location / {<br>                try_files $uri $uri.html $uri/ =404;<br>        }<br><br><br>    listen 443 ssl; # managed by Certbot<br>    ssl_certificate /etc/letsencrypt/live/snpranav.com/fullchain.pem; # managed by Certbot<br>    ssl_certificate_key /etc/letsencrypt/live/snpranav.com/privkey.pem; # managed by Certbot<br>    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot<br>    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot<br><br><br>}</pre><p>Note — domain.tld refers to your own domain</p><p>Add this snippet inside the server block</p><pre>location ^~ /subdirectory {<br>      proxy_set_header X-Real-IP $remote_addr;<br>      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>      proxy_set_header Host $http_host;<br>      proxy_set_header X-NginX-Proxy true;<br>      proxy_set_header X-Forwarded-Proto $scheme;<br>      proxy_pass http://localhost:2368;<br>      proxy_redirect off;<br>}</pre><p>Finally, the NGINX configuration file should look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/782801131b6eb1aca0077c2c1604a858/href">https://medium.com/media/782801131b6eb1aca0077c2c1604a858/href</a></iframe><p>Now, visit <a href="https://domain.tld/subdirectory/ghost/,">https://domain.tld/subdirectory/ghost/,</a> and you should be able to create your Ghost Blog account as shown below.</p><p>Once you configure all the above setting properly, you will not get any kind of <a href="https://developers.google.com/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content">mixed content errors</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lkbpaYkBSsmSoVgq.PNG" /><figcaption><a href="https://domain.tld/subdirectory/ghost/">https://domain.tld/subdirectory/ghost/</a></figcaption></figure><p>Happy Blogging!</p><p>If you have any questions or any suggestions/ideas. Hit me up in the comments section :)</p><p>Stay up to date with my medium posts by following <a href="https://medium.com/@pranav.shikarpur">Pranav Shikarpur</a> on medium.</p><p>My Website- <a href="https://snpranav.com/?utm_medium=footer&amp;utm_source=blog">snpranav.com</a></p><h3>Credits</h3><p><a href="https://medium.com/@snnithya">Nithya Shikarpur</a>- Reviewed this post</p><p><em>Originally published at </em><a href="https://snpranav.com/blog/ghost-in-subdirectory-over-ssl/?utm_medium=footer-click&amp;utm_source=medium.com"><em>snpranav.com</em></a><em> on March 2, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cd200e02524" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-to-startup-to-life-by-pranav/ghost-blog-in-a-subdirecotory-over-ssl-4cd200e02524">Setup Ghost Blog in a Subdirecotory over SSL on NGINX</a> was originally published in <a href="https://medium.com/tech-to-startup-to-life-by-pranav">Pranav’s Tech Blog (Archived)</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure GitHub webhooks with a web server]]></title>
            <link>https://medium.com/tech-to-startup-to-life-by-pranav/configure-github-webhooks-with-an-apache-web-server-efc40214dc27?source=rss-5f5fe931997d------2</link>
            <guid isPermaLink="false">https://medium.com/p/efc40214dc27</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Pranav Shikarpur]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 16:58:29 GMT</pubDate>
            <atom:updated>2019-03-02T16:11:35.615Z</atom:updated>
            <content:encoded><![CDATA[<h3>Configure GitHub Webhooks with a Web Server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xKbG9JItgMomaCxZELzeWg.png" /><figcaption>Cover Image</figcaption></figure><p>We’ve all faced it! After pushing many updates to <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a>, you realize that you haven’t pulled from the git server onto your web server. Soon, you cannot see your updates on the web server. So, how do you solve this problem? How do you make the git server sync with your web server?</p><h3>Webhooks</h3><h4>What are Webhooks?</h4><blockquote>Webhooks are “user-defined HTTP callbacks”. They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URL configured for the webhook. Users can configure them to cause events on one site to invoke behaviour on another. The action taken may be anything.</blockquote><blockquote>— <a href="https://z.snpranav.com/medium/r/webhook-wiki">Wikipedia</a></blockquote><p>If you didn’t understand a word of that definition, webhooks are HTTP callbacks that do some action when an event is triggered. In this case, we will be configuring the webhook to execute a pull command from the shell when a push event is made to the git server.</p><p>PS- If you haven’t set up your git server on <a href="https://github.com/">github.com</a>, I would advise you to do so now! If you’re wondering what the word “git” means, learn git off the official website: <a href="https://git-scm.com/">git-scm.com</a>.</p><h4>Creating a Webhook</h4><p>Now that we understand the functioning of webhooks, let’s create our first webhook!</p><p><strong><em>Note- Although I have added the bitbucket logo on the cover image, I haven’t tried it out on a BitBucket repository. There shouldn’t be much of a difference while configuring bitbucket webhooks. Nevertheless, hit me up in the comments section if you run into problems!</em></strong></p><p><strong>GitHub.com</strong></p><p>Log on to <a href="https://z.snpranav.com/medium/r/github">github.com</a> and push some code into your repository. Go to Settings-&gt;Webhooks-&gt;Add webhook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ONqoUPEyOwYnJ9pfpPHYA.png" /><figcaption>Creating a Webhook</figcaption></figure><h4>What do these fields represent?</h4><p><strong>Payload URL- </strong>This is the URL the webhook will ping when an event is completed on the GIT server.</p><p><strong>Content Type- </strong>We aren’t going to worry about this because we aren’t going to configure the webhook with a secret as the verification process is time-consuming.</p><p><strong>Secret- </strong>Again, I’m not going to configure the webhook with a secret as the verification process is time-consuming. However, I have a way to work around this problem.</p><p><strong>SSL Verification (</strong><a href="https://z.snpranav.com/medium/r/digicert-ssl"><strong>Secure Socket Layer</strong></a><strong>)- </strong>If your payload URL has an SSL certificate (<strong>https://</strong>domain.tld), then you will have an option to enable SSL verification which will encrypt all the connections. Else, if your payload URL does not have an SSL certificate (<strong>http://</strong>domain.tld), then you will not see the option.</p><p><strong>Events- </strong>Define when the webhook should be triggered.</p><p><strong>Active- </strong>Leave the box checked <strong>(Recommended)</strong>. If you want to disable the webhook (<strong>NOT RECOMMENDED</strong>), then uncheck the box.</p><p>More information on the official website <a href="https://developer.github.com/webhooks/creating/">here</a>.</p><p>We have configured the webhook!</p><h3>Fixing User Errors on Ubuntu</h3><p><strong><em>Note- I have only faced this error on Ubuntu as the OS has predefined users on setup; furthermore, the root user isn’t the user performing operations for an Apache/Nginx Server on Ubuntu.</em></strong></p><h4>Figuring out the user <strong><em>performing operations on the web server</em></strong></h4><p>To do this, create a .php file in your public directory and add the following code.</p><pre>&lt;?php<br>     echo shell_exec(&#39;whoami&#39;);<br>?&gt;</pre><p>Visit the page using a browser and see the output. The output displays the web server’s user that is performing the operations on the web server.</p><p>If you’re using Ubuntu 18.04 LTS, the user will most probably be “www-data”. I will use “www-data” as the user throughout this tutorial.</p><h3>Generating SSH keys for the <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a> Repository (<em>Only for Private Repositories</em>)</h3><p><strong>Note- Skip the following steps till the next breakpoint if you are not using a <em>Private Repository.</em></strong></p><p>While pulling from the GitHub repository, you cannot use the <em>HTTPS</em><strong> </strong>method if you are using a <em>private repository. </em>Moreover, you will have to use the <em>SSH </em>method as it only requires the SSH key for authentication while pulling from the repository.</p><p>To use the SSH method, we have to generate an SSH key with the web server’s user “www-data” (in your case this might be a different user). Run this command:</p><pre>$ sudo -Hu www-data ssh-keygen -t rsa</pre><p>“-Hu www-data” part is running the command as the “www-data” user in this case.</p><p>Save the SSH key in the default folder and <strong>DO NOT SET A PASSPHRASE</strong>.</p><p><em>Note: If you get a “Permissions Error”, then you will have to grant access to www-data to access the /var/www/ directory. To do this, run the following command</em></p><pre>$ sudo chown www-data:www-data /var/www/</pre><p><em>Note- If you get an error which says that the folder does not exist, then you might have to manually create the folder by running the following command.</em></p><pre>$ sudo mkdir /var/www/.ssh/</pre><h4>Adding our SSH key to GitHub</h4><p>Once you’ve created the SSH key, got to the /var/www/.ssh/ folder by using the following command</p><pre>$ cd /var/www/.ssh/</pre><p>Copy the SSH key from here from the output of the following command (Assuming your key is called id_rsa)</p><pre>$ cat id_rsa.pub</pre><p>In the <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a> repository, go to Settings-&gt;Deploy Keys-&gt;Add Deploy Key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qP9dVFrKIuvKL5CPoz9eQ.png" /><figcaption>Adding a Deploy Key</figcaption></figure><h4>What do these fields represent?</h4><p><strong>Title- </strong>Key’s name (Name it anything you want)</p><p><strong>Key- </strong>Paste the key you copied in the previous step</p><p><strong>Allow write access- </strong>Since we’re just going to be pulling from the repository, we do not need write access. However, if you want to push to the repository, then you need to “Allow write access”.</p><p>More information about adding deploy keys <a href="https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys">here</a>.</p><h3>Configuring the payload URL</h3><p>Create a new file called “webhooks-file-name.php” (Same name as entered while creating the webhook)</p><p>Add the following code to the file</p><pre>&lt;?php<br>     echo shell_exec(&#39;git pull&#39;);<br>?&gt;</pre><p>Congratulations! You have successfully configured a webhook with <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a>!</p><p>Now push code to your <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a> repository and watch the magic happen!</p><h3>Adding security to hide the payload URL from the public (OPTIONAL)</h3><p>Remember when I said that I had a way to work around not adding a “Secret” to the webhook. The solution is to pass arguments through the URL and verify them. The URL could be something like this</p><pre>https://domain.tld/webhooks-file-name.php?arg1=...&amp;arg2=...</pre><p>Let’s verify that the arguments. Add the following code to the webhooks-file-name.php file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/466a170650744c54ef14b9f22da18b34/href">https://medium.com/media/466a170650744c54ef14b9f22da18b34/href</a></iframe><p>Now the webhook has been configured with some form of security!</p><p>If you have any questions or any suggestions/ideas. Hit me up in the comments section :)</p><p>Stay up to date with my medium posts by following <a href="https://medium.com/u/5f5fe931997d">Pranav Shikarpur</a> on medium.</p><p>My Website- <a href="https://snpranav.com/?utm_medium=footer&amp;utm_source=medium">snpranav.com</a>.</p><h3>Credits</h3><p><a href="https://medium.com/u/8bfe53182a7">Mohammed Suhail Cs</a>- Guided me through parts of the solution’s implementation</p><p><a href="https://medium.com/u/3a1836819431">Nithya Shikarpur</a>- Reviewed this post</p><p><em>Officially published at </em><a href="https://snpranav.com/blog/configure-git-webhooks-with-server/?utm_medium=footer-click&amp;utm_source=medium.com"><em>snpranav.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efc40214dc27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-to-startup-to-life-by-pranav/configure-github-webhooks-with-an-apache-web-server-efc40214dc27">Configure GitHub webhooks with a web server</a> was originally published in <a href="https://medium.com/tech-to-startup-to-life-by-pranav">Pranav’s Tech Blog (Archived)</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embed Medium Blog Posts in Website]]></title>
            <link>https://medium.com/tech-to-startup-to-life-by-pranav/retrieve-all-your-medium-blogs-and-display-it-on-your-website-in-a-neat-fashion-89a923725cbf?source=rss-5f5fe931997d------2</link>
            <guid isPermaLink="false">https://medium.com/p/89a923725cbf</guid>
            <category><![CDATA[bootstrap-4]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[medium-blogs-to-website]]></category>
            <category><![CDATA[html5]]></category>
            <dc:creator><![CDATA[Pranav Shikarpur]]></dc:creator>
            <pubDate>Thu, 29 Nov 2018 10:22:35 GMT</pubDate>
            <atom:updated>2019-03-02T16:12:49.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_M38Ef-pF1MZAeqnOK2A8g.png" /></figure><p>I am the lead web developer at <a href="https://whywaste.io/">Why Waste?</a>. At one point in time, we at <a href="https://medium.com/u/65415a55d6f7">Why Waste?</a> wanted to start writing blogs on medium. After we published a few, I wondered whether it would it would be possible to fetch all user blogs off medium and get it to the website’s subdomain (<a href="https://medium.whywaste.io/">medium.whywaste.io</a>).</p><h3>Background Research</h3><p>After doing some research I found out that <a href="https://medium.com/u/504c7870fdb6">Medium</a> had a free custom domain service where you could basically create another medium page on one of your website’s custom domain that would only contain your profile and it’s blog posts; however, this service is not free anymore and currently costs 75$ (Reference- <a href="https://medium.com/u/891aedd362e6">Benjamin Dada, MSc.</a>’s post- <a href="https://medium.com/benjamin-dada/medium-now-charges-75-to-set-up-a-custom-domain-54ab54117fd4">https://medium.com/benjamin-dada/medium-now-charges-75-to-set-up-a-custom-domain-54ab54117fd4</a>). Parts of the Javascript logic, in this blog post, for fetching blog posts were taken from <a href="https://medium.com/u/fc23f67a0fc5">Jason Matthew</a>’s <a href="https://medium.jasonmdesign.com/display-medium-articles-on-your-site-d772b3b05779">blog post</a>.</p><h3>The purpose of writing this blog post</h3><p>I have found other blog posts regarding this on the internet, some which have no easy front-end design implementation, some which are poorly described, and some which are useless XD. I can assure you that this blog post is easy to understand and seamlessly implementable if you have an understanding of the Prerequisites.</p><h3>Prerequisite Knowledge:</h3><p>HTML5, JavaScript, <a href="https://jquery.com/">JQuery</a>(Just to make the JavaScript cleaner :P), and <a href="https://getbootstrap.com/">Bootstrap 4</a>.</p><p>If you do not have any knowledge about these, then you can either learn it off <a href="https://medium.com/u/fb8d78e7d205">Treehouse</a> (<a href="https://teamtreehouse.com/">teamtreehouse.com</a>) or W3 Schools(<a href="https://w3schools.com/">w3schools.com</a>) or <a href="https://youtube.com/">Youtube</a>.</p><h3>Steps</h3><h4>Getting user feed in JSON format</h4><p>We can look at a user’s feed in JSON by adding “/latest?format=json” (medium.com/@username/latest?format=json); however, that is going to throw a CORS(Cross-Origin Resource Sharing) error. In simple words, CORS error implies that the web server is preventing us from gaining unauthorized access to a web application from a different origin (domain, protocol, and port). You can read up more about CORS error <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors">here</a>. Nevertheless, if you try and use “/latest?format=json”, you will get the error below which basically means it is a dead end :(.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*hEcQpTasjU-LbZiiQaLStA.png" /><figcaption>Google Chrome Developer Console Error Message due to CORS error</figcaption></figure><h4>RSS to the Saviour</h4><p>Luckily, medium lets you extract <a href="https://en.wikipedia.org/wiki/RSS">RSS feed</a> from a user’s profile. Go to medium.com/feed/@username to get your RSS feed (More details <a href="https://help.medium.com/hc/en-us/articles/214874118-RSS-feeds">here</a>). Now, we can use <a href="https://rss2json.com/">rss2json.com</a> to convert our RSS feed to JSON using their API and get the JSON data!</p><p>Now that we have our JSON data, let’s dive into the code!</p><h4>Including Libraries</h4><p>First, let us include <strong>JQuery </strong>in our code:</p><pre>&lt;script src=&quot;<a href="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js</a>&quot;&gt;&lt;/script&gt;</pre><p>Note- I like using the Google JQuery CDN (<a href="https://en.wikipedia.org/wiki/Content_delivery_network">Content Delivery Network</a>). Nevertheless, you could include JQuery in whatever way you wish to. (More information about including JQuery <a href="https://jquery.com/download/">here</a>)</p><p>While we are at it let’s also include the Bootstrap 4 CSS library. Again, I have used their CDN, but you can include it however you want!</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css&quot; integrity=&quot;sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO&quot; crossorigin=&quot;anonymous&quot;&gt;</pre><p>We’re done with importing all the libraries needed! Now let’s start getting some data.</p><h4>Getting feed from the API</h4><p>Once you convert your RSS feed to JSON on the rsstojson.com converter API, you will get a URL that looks like this- <a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a>. We need to <strong>GET</strong> data from this url.</p><p>We will use the $.get() method which is an AJAX (<strong>A</strong>synchronous <strong>J</strong>avaScript <strong>A</strong>nd <strong>X</strong>ML- You don’t have to learn AJAX for this tutorial; however, you can find more information <a href="https://www.w3schools.com/xml/ajax_intro.asp">here</a>) short hand provided by JQuery.</p><p>Syntax for $.get() is</p><pre>$.get(<em>URL,data,function(data,status,xhr),dataType)</em></pre><p>This looks intimidating at first, but it isn’t. I’ll explain each parameter:</p><ul><li>URL- The URL, you want to request data from (Required)</li><li>data- Specifies data to send to the server along with the request (Optional)</li><li>function- <a href="https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced">Callback function</a> if it recieves a successful response (Required in this case)</li><li>dataType- Specify the type of response to recieve. By default, JQuery takes care of this (Optional)</li></ul><p>More information on the $.get() method <a href="https://www.w3schools.com/jquery/ajax_get.asp">here</a></p><p><strong>Let’s use this function in our code</strong></p><p>Defining parameters in our use case:</p><ul><li>URL- <a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a> (Or whatever your JSON converted url might be)</li><li>data- Optional, but you can send the RSS feed URL (In my case- <a href="https://medium.com/feed/@mediumstaff">https://medium.com/feed/@mediumstaff</a>)</li></ul><p>Now, let’s define our callback function:</p><pre>var data = {rss: &quot;<a href="https://medium.com/feed/@mediumstaff">https://medium.com/feed/@mediumstaff</a>&quot;}<br>$.get(<a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a>, data, funciton(response){<br>//Checking Response Status<br><strong>if </strong>(response.status == &#39;ok&#39;) {<br>   //Defining a variable where I create my response data<br>   <strong>var </strong>output = &#39;&#39;;<br>   //Response...<br>  }<br>});</pre><h4>Let’s iterate to get multiple posts</h4><p>To iterate through the posts let’s use, the JQuery $.each() method.</p><p>Syntax for the $.each() method</p><pre>$.each(object, <strong>function</strong>( index, value ) {<br>    //Code to be Iterated<br>}</pre><p><strong>Note</strong>- The $.each() function is not the same as $(selector).each(), which is used to iterate, exclusively, over a jQuery object. More information about the $.each function over <a href="http://api.jquery.com/jquery.each/">here</a>.</p><p><strong>Let’s iterate through the posts in our code</strong></p><pre>var data = {rss: &quot;<a href="https://medium.com/feed/@mediumstaff">https://medium.com/feed/@mediumstaff</a>&quot;}<br>$.get(<a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a>, data, funciton(response){<br>//Checking Response Status<br><strong>if </strong>(response.status == &#39;ok&#39;) {<br>   //Defining a variable where I create my response data<br>   <strong>var </strong>output = &#39;&#39;;<br>   //Response...<br>   $.each(response.items, <strong>function </strong>(k, item) {<br>      //Iteration<br><strong>      return </strong>k &lt; 10;<br>   });<br> }<br>});</pre><p><strong>Note</strong>- If you are confused about why I am returning k&lt;10. What I am basically doing is telling the iterator to end the loop once the index (k) becomes 9 (index starts from 0). The <a href="https://medium.com/u/504c7870fdb6">Medium</a> RSS feed unfortunately gives only 10 of the user’s latest blog posts; hence, we can only retrieve 10 blog posts.</p><p>Great! We have successfully completed getting posts from the API!</p><h3>Displaying data on the front-end</h3><p>Before we start, the reason I’m using Bootstrap 4 and not my own custom CSS is because Bootstrap is much faster to deploy. I know how to create my own custom CSS files, but I don’t want to spend too much time on that :)</p><p>Now, let’s use some HTML and Bootstrap 4.</p><p>First, I want to add a <a href="https://getbootstrap.com/docs/4.1/components/jumbotron/">Jumbotron</a> to give a nice and bold header.</p><pre>&lt;body&gt;<br>&lt;div class=&quot;container mt-5 pt-5&quot; id=&quot;medium&quot;&gt;<br>    &lt;div class=&quot;jumbotron text-center&quot;&gt;<br>        &lt;div id=&quot;logo&quot;&gt;&lt;/div&gt;<br>        &lt;h1 class=&quot;display-4 mb-3&quot;&gt;@mediumstaff&#39;s Posts&lt;/h1&gt;<br>        &lt;a class=&quot;btn btn-outline-primary btn-lg&quot; href=&quot;https://medium.com/@mediumstaff&quot; target=&quot;_blank&quot; role=&quot;button&quot;&gt;View all posts&lt;/a&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;row&quot; id=&quot;jsonContent&quot;&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;</pre><p>I have also defined a div with the id of <strong>jsonContent </strong>because we are going to feed our JSON data into this div.</p><p>Now let’s add the JavaScript to get our data</p><pre><strong>var </strong>$content = $(&#39;#jsonContent&#39;);<br><strong>var </strong>data = {<br>    rss: &#39;https://medium.com/feed/@mediumstaff&#39;<br>};<br>$.get(&#39;<a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a>&#39;, data, <strong>function </strong>(response) {<br>    <strong>if </strong>(response.status == &#39;ok&#39;) {<br>        $(&quot;#logo&quot;).append(`&lt;img src=&quot;${response.feed[&quot;image&quot;]}&quot; class=&quot;rounded mx-auto d-block&quot;&gt;`)<br><strong>var </strong>output = &#39;&#39;;<br>        $.each(response.items, <strong>function </strong>(k, item) {<br>            output += `&lt;div class=&quot;card mb-3 mx-auto mr-5 &quot; style=&quot;width: 20rem;&quot;&gt;`; //Adding Each Post into a card</pre><pre><strong>var </strong>tagIndex = item.description.indexOf(&#39;&lt;img&#39;); <br>//Find where the img tag starts</pre><pre><strong>var </strong>srcIndex = item.description.substring(tagIndex).indexOf(&#39;src=&#39;) + tagIndex; //Find where the src attribute starts</pre><pre><strong>var </strong>srcStart = srcIndex + 5; //Find where the actual image URL starts; 5 for the length of &#39;src=&quot;&#39;</pre><pre><strong>var </strong>srcEnd = item.description.substring(srcStart).indexOf(&#39;&quot;&#39;) + srcStart; //Find where the URL ends<br>            <br><strong>var </strong>src = item.description.substring(srcStart, srcEnd); // Extract just the URL<br>            <br>output += `&lt;img src=&quot;${src}&quot; class=&quot;card-img-top&quot; alt=&quot;Cover image&quot;&gt;`; //Adding the image to the Card<br>            <br>output += `&lt;div class=&quot;card-body&quot;&gt;`;    //Defining the Card body<br>            <br>output += `&lt;h5 class=&quot;card-title&quot;&gt;&lt;a href=&quot;${item.link}&quot;&gt;${item.title}&lt;/a&gt;&lt;/h5&gt;`;   //Hyperlinking the title of the card to the post</pre><pre><strong>var </strong>yourString = item.description.replace(/&lt;img[^&gt;]*&gt;/g,&quot;&quot;); //We do not want an image in the description so I replace the images with &quot;&quot; (Empty text)<br>            <br>yourString = yourString.replace(&#39;h4&#39;, &#39;p&#39;); //Replacing h4 tags with p tags<br>            <br>yourString = yourString.replace(&#39;h3&#39;, &#39;p&#39;); //Replacing h3 tags with p tags<br>            <br><strong>var </strong>maxLength = 120; // maximum number of characters to extract<br>            <br>//trim the string to the maximum length<br><strong>var </strong>trimmedString = yourString.substr(0, maxLength);</pre><pre>//re-trim if we are in the middle of a word<br>trimmedString = trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(&quot; &quot;)))<br>            <br>output += `&lt;p class=&quot;card-text&quot;&gt;${trimmedString}...&lt;/p&gt;`;<br>            <br>output += `&lt;a href=&quot;${item.link}&quot; class=&quot;btn btn-outline-success&quot;&gt;Read More&lt;/a&gt;`;    //Adding a Read More button that links to the original post.<br>            <br>output += &#39;&lt;/div&gt;&lt;/div&gt;&#39;;<br>            <br><strong>return </strong>k &lt; 10;<br>        <br>});<br>        <br>$content.html(output);   //Feeding the output into the div with id jsonContent<br>    <br>}<br>});</pre><p>The code might look slightly messed up, but don’t worry, I have created a codepen project, so that you can take my code (Link is at the bottom of this post). This is only for your understanding purpose.</p><p>I defined a variable called output, which stores the content of each post. I have tried to put a lot of comments explaining each line of the code. I have used a <a href="https://getbootstrap.com/docs/4.1/components/card/#example">Bootstrap card</a> to display all the elements in an orderly fashion.</p><p>I’ve added comments at each line to help you understand the code.</p><p>Link to the complete code is given at the bottom of the next section</p><h3>Optional Section that will make the front end design aesthetic</h3><h4>JavaScript Promise</h4><p>Let’s understand what a JavaScript promise is and we’ll later understand how it is going to be useful later on in our code.</p><p><strong>What is a Promise?</strong></p><p>No, I wasn’t referring to the promise you keep with your loved ones. I am referring to a JavaScript promise.</p><blockquote>“The <strong>Promise</strong> object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.”</blockquote><blockquote>Reference- <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">MDN web docs</a></blockquote><p>If you still didn’t understand what a promise is, it is a object which returns a status of success or error (aka resolve, reject).</p><p>Let’s take a look at an example. Let’s say you want to run one JavaScript function first and then the next because you have to pass in the value from the result of the first function into the second. However, if you just call them separately, there is a possibility that the second function can finish before the first and throw an error as it hasn’t received the parameter from the first function. Promise helps us tackle this problem easily. We wait for a response and run the next function. Simple? Isn’t it?</p><p>Now, that you’ve understood Promises, let’s dive in to applying it!</p><h4>Adding dynamic Pagination</h4><p>If you want to present the cards over different pages, you should go through this section. (Recommended)</p><p>If you don’t know what pagination means, pagination are the controls that you see at the bottom of a page with a lot of content that helps you navigate through the content on multiple pages. (More information on pagination <a href="https://www.w3schools.com/bootstrap/bootstrap_pagination.asp">here</a>)</p><p><strong>Adding it in our Code</strong></p><pre>$(function () {<br>            //Creating a new Promise and passing resolve as the function&#39;s parameter. The arguments passed into resolve method will execute only after a particular line of code is done.<br>            var mediumPromise = new Promise(function (resolve) {<br>            var $content = $(&#39;#jsonContent&#39;);<br>            var data = {<br>                rss: &#39;<a href="https://medium.com/feed/@mediumstaff&#39;">https://medium.com/feed/@mediumstaff&#39;</a><br>            };<br>            $.get(&#39;<a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff">https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff</a><a href="https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2F%40mediumstaff&amp;api_key=eb6cbrjxm0twrvmx2tiqc1ueqqpyq5wtuyl5mwhf&amp;count=30&#39;">&#39;</a>, data, function (response) {<br>                if (response.status == &#39;ok&#39;) {<br>                    $(&quot;#logo&quot;).append(`&lt;img src=&quot;${response.feed[&quot;image&quot;]}&quot; class=&quot;rounded mx-auto d-block&quot;&gt;`)<br>                    var output = &#39;&#39;;<br>                    $.each(response.items, function (k, item) {<br>                        output += `&lt;div class=&quot;card mb-3 mx-auto mr-5 &quot; style=&quot;width: 20rem;&quot;&gt;`;<br>                        var tagIndex = item.description.indexOf(&#39;&lt;img&#39;); // Find where the img tag starts<br>                        var srcIndex = item.description.substring(tagIndex).indexOf(&#39;src=&#39;) + tagIndex; // Find where the src attribute starts<br>                        var srcStart = srcIndex + 5; // Find where the actual image URL starts; 5 for the length of &#39;src=&quot;&#39;<br>                        var srcEnd = item.description.substring(srcStart).indexOf(&#39;&quot;&#39;) + srcStart; // Find where the URL ends<br>                        var src = item.description.substring(srcStart, srcEnd); // Extract just the URL<br>                        output += `&lt;img src=&quot;${src}&quot; class=&quot;card-img-top&quot; alt=&quot;Cover image&quot;&gt;`;<br>                        output += `&lt;div class=&quot;card-body&quot;&gt;`;<br>                        output += `&lt;h5 class=&quot;card-title&quot;&gt;&lt;a href=&quot;${item.link}&quot;&gt;${item.title}&lt;/a&gt;&lt;/h5&gt;`;<br>                        var yourString = item.description.replace(/&lt;img[^&gt;]*&gt;/g,&quot;&quot;); //replace with your string.<br>                        yourString = yourString.replace(&#39;h4&#39;, &#39;p&#39;);<br>                        yourString = yourString.replace(&#39;h3&#39;, &#39;p&#39;);<br>                        var maxLength = 120; // maximum number of characters to extract<br>                        //trim the string to the maximum length<br>                        var trimmedString = yourString.substr(0, maxLength);<br>                        //re-trim if we are in the middle of a word<br>                        trimmedString = trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(&quot; &quot;)))<br>                        output += `&lt;p class=&quot;card-text&quot;&gt;${trimmedString}...&lt;/p&gt;`;<br>                        output += `&lt;a href=&quot;${item.link}&quot; class=&quot;btn btn-outline-success&quot;&gt;Read More&lt;/a&gt;`;<br>                        output += &#39;&lt;/div&gt;&lt;/div&gt;&#39;;<br>                        return k &lt; 10;<br>                    });<br>                    resolve($content.html(output)); //Passing the output into the resolve function. This means that once it writes the output into the div, it will send a success response to carry out the next function in the .then() method.<br>                }<br>            });<br>            });</pre><pre>//.then() method executes the function after the Promise is resolved<br>mediumPromise.then(function()<br>            {<br>                //Pagination<br>                pageSize = 3;</pre><pre>var pageCount = $(&quot;.card&quot;).length / pageSize; //Calculating the number of pages it the content needs to spread over</pre><pre>//Running a loop to add the pagination links(numbers) dynamically<br>for (var i = 0; i &lt; pageCount; i++) {<br>                    $(&quot;#pagin&quot;).append(`&lt;li class=&quot;page-item&quot;&gt;&lt;a class=&quot;page-link&quot; href=&quot;#&quot;&gt;${(i + 1)}&lt;/a&gt;&lt;/li&gt; `); //Appending the list elements to the unordered list(ul) in the HTML code<br>                }</pre><pre>                //Highlighting the first page number on load by giving it the class &quot;active&quot;<br>                $(&quot;#pagin li:nth-child(1)&quot;).addClass(&quot;active&quot;);</pre><pre>                //showpage adds the content on to each page<br>                showPage = function (page) {<br>                    $(&quot;.card&quot;).hide();<br>                    $(&quot;.card&quot;).each(function (n) {<br>                        if (n &gt;= pageSize * (page - 1) &amp;&amp; n &lt; pageSize * page)<br>                            $(this).show();<br>                    });<br>                }</pre><pre>//On page load, It will display contents of first page<br>showPage(1);</pre><pre>//Highlights each page number(list element) onclick<br>$(&quot;#pagin li&quot;).click(function () {<br>                    $(&quot;#pagin li&quot;).removeClass(&quot;active&quot;);<br>                    $(this).addClass(&quot;active&quot;);<br>                    showPage(parseInt($(this).text()))<br>                });<br>            });<br>        });</pre><p>Now, you should see links like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*uuDbFkefrmYyrmkqQemH9A.png" /><figcaption>Dynamic Pagination</figcaption></figure><p>Yay! We’re done!</p><p>Access to the complete code- <a href="https://z.snpranav.com/WSEtax">https://z.snpranav.com/WSEtax</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fsnpranav%2Fembed%2Fpreview%2FLXBVPG%3Fheight%3D600%26slug-hash%3DLXBVPG%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fsnpranav%2Fpen%2FLXBVPG&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F2618121.LXBVPG.small.95e38da5-2823-4f29-81cd-0bd38158c88a.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/17289784dac579845b033762f3c492dc/href">https://medium.com/media/17289784dac579845b033762f3c492dc/href</a></iframe><p>If you have any questions about the code or any other suggestions/ideas. Hit me up in the comments section :)</p><p>Stay up to date with my medium posts by following <a href="https://medium.com/u/5f5fe931997d">Pranav Shikarpur</a> on medium.</p><p>My Website- <a href="https://snpranav.com/?utm_medium=footer&amp;utm_source=medium">snpranav.com</a></p><h3>Credits</h3><p><a href="https://medium.com/u/3a1836819431">Nithya Shikarpur</a>- Reviewed this post</p><p><em>Officially published at </em><a href="https://snpranav.com/blog/medium-posts-on-website/?utm_medium=footer-click&amp;utm_source=medium.com"><em>snpranav.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89a923725cbf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-to-startup-to-life-by-pranav/retrieve-all-your-medium-blogs-and-display-it-on-your-website-in-a-neat-fashion-89a923725cbf">Embed Medium Blog Posts in Website</a> was originally published in <a href="https://medium.com/tech-to-startup-to-life-by-pranav">Pranav’s Tech Blog (Archived)</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>