<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Erik Karlsson</title>
    <description>The latest articles on Forem by Erik Karlsson (@erikkarlsson).</description>
    <link>https://forem.com/erikkarlsson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F644090%2Fafae206c-952b-4975-9978-bdedb597558a.jpeg</url>
      <title>Forem: Erik Karlsson</title>
      <link>https://forem.com/erikkarlsson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/erikkarlsson"/>
    <language>en</language>
    <item>
      <title>How to add a preview of your React (or any other) site when sharing it</title>
      <dc:creator>Erik Karlsson</dc:creator>
      <pubDate>Tue, 15 Jun 2021 09:41:50 +0000</pubDate>
      <link>https://forem.com/erikkarlsson/how-to-add-a-preview-of-your-react-or-any-other-site-when-sharing-it-2fhf</link>
      <guid>https://forem.com/erikkarlsson/how-to-add-a-preview-of-your-react-or-any-other-site-when-sharing-it-2fhf</guid>
      <description>&lt;p&gt;Are you struggling with having your website preview looking something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwo3slvkn6lyt04t5kre7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwo3slvkn6lyt04t5kre7.png" alt="No picture in preview"&gt;&lt;/a&gt; &lt;br&gt;
Whenever you're sharing it on linkedin/facebook/etc, when you're really looking for something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flm503wacw75zcjpkf2ys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flm503wacw75zcjpkf2ys.png" alt="Man in picture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had this exact same issue and solved it. Let me show you how.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The magic is&lt;/strong&gt; all in the &lt;code&gt;index.html&lt;/code&gt; file. Sites such as Linkedin and facebook, and even Discord, use something called the Open Graph Protocol, and this allows you to specify how you want your preview to look like.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This you will&lt;/strong&gt; specify in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag where you have your usual &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags  such as &lt;code&gt;&amp;lt;meta charset="utf-8" /&amp;gt;&lt;/code&gt; etc.&lt;/p&gt;

&lt;p&gt;The syntax is: &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:title"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Title-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:image"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"File-path"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:url"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Canonical-url"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:type"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"website"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;These four tags&lt;/strong&gt; are required. There's also optional tags, the most commonly used being &lt;code&gt;og:description&lt;/code&gt;. You can read more about all the types of tags &lt;a href="https://ogp.me/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The image can&lt;/strong&gt; be anything you want - from very abstract to an actual preview of your site. I made mine by squeezing up my site and finding the right place to screen dump, then I put it in the &lt;code&gt;assets&lt;/code&gt; folder, and I declared it by: ```property="og:image"&lt;br&gt;
&lt;br&gt;
 content="&lt;a href="https://erikkarlsson.dev/assets/prev.png" rel="noopener noreferrer"&gt;https://erikkarlsson.dev/assets/prev.png&lt;/a&gt;"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Together with everything else in the header it looked like this:
```HTML


&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1" /&amp;gt;

&amp;lt;meta property="og:type" content="website"&amp;gt;
&amp;lt;meta property="og:title" content="Erik Karlsson"&amp;gt;
&amp;lt;meta property="og:description" content="Portfolio page made by Erik in React."&amp;gt;
&amp;lt;meta property="og:image" content="https://erikkarlsson.dev/assets/prev.png"&amp;gt;
&amp;lt;meta property="og:url" content="https://erikkarlsson.dev"&amp;gt;

...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Which looks like this when sharing it on Linkedin:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v7x8s7mhbw0xg1f54c4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v7x8s7mhbw0xg1f54c4.png" alt="After"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's how you do it! Check out &lt;a href="https://developers.facebook.com/docs/sharing/webmasters/" rel="noopener noreferrer"&gt;this&lt;/a&gt; if you want to learn more about this topic.&lt;/p&gt;

</description>
      <category>react</category>
      <category>seo</category>
      <category>html</category>
      <category>opengraph</category>
    </item>
    <item>
      <title>Why it's not worth setting up a server yourself - even to save money</title>
      <dc:creator>Erik Karlsson</dc:creator>
      <pubDate>Sun, 13 Jun 2021 19:32:17 +0000</pubDate>
      <link>https://forem.com/erikkarlsson/why-it-s-not-worth-setting-up-a-server-yourself-even-to-save-money-3ag9</link>
      <guid>https://forem.com/erikkarlsson/why-it-s-not-worth-setting-up-a-server-yourself-even-to-save-money-3ag9</guid>
      <description>&lt;p&gt;&lt;strong&gt;I recently made myself a pretty portfolio page in React. Now it was time to set up a server to host it. After some &lt;a href="https://www.youtube.com/watch?v=QdHvS0D1zAI" rel="noopener noreferrer"&gt;inspiration&lt;/a&gt; I went on a journey to set it up via Raspberry Pi. This felt like the truest way. Not gonna use some pesky easy-hosting on some GoDaddy-site, it was time to do it the real way.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So I ordered&lt;/strong&gt; a sweet &lt;em&gt;rpi 4 2gb&lt;/em&gt; starter kit, and I felt like a child on christmas. I was actually stuck with Windows on my Surface Laptop, for which there are no keyboard/mouse drivers for Linux -&amp;gt; so it was very nice to finally work in a GNU/Linux environment again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After I received&lt;/strong&gt; my Pi, I went through the jazz - downloaded everything I needed and - bear with me if you've not done this before, but I: set up a proxy to my localhost/npm-build in nginx, did port-forwarding in my router and set up the DNS records to point to my ip, together with a dynamic DNS service on CloudFlare to continously update my IP when it changes (sorry, no static IP unless you have a business account my ISP told me). This took some time, but it was a learning experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I also set up&lt;/strong&gt; docker + docker compose for nginx proxy manager, a well-recommended admin tool that manages your nginx projects for you and does a free SSL for you called Let's Encrypt. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then it hit me.&lt;/strong&gt; I couldn't log in to the admin panel I just docker-composed. Somehow, it was a bad gateway (?). A big mystery, of which many other people had the exact same issue, and everyone had a different solution, if they had any. Some needed to change a tiny thing, like which DBMS they use, or a big thing, and some just neeeded to wait 10 minutes, or a day, and then it suddenly worked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I literary spent&lt;/strong&gt; the next 10 hours on this, seemingly tiny issue, to simply gain access to my own Admin Panel. It so happened that the documentation on the official site was incorrect for raspberry pies, and there actually was &lt;a href="https://dbtechreviews.com/2020/06/install-nginx-proxy-manager-on-a-raspberry-pi-4/" rel="noopener noreferrer"&gt;a proper way&lt;/a&gt; to do it for my tiny device. Well, I followed this excellent guide to the tea. I tried to log in to the admin panel again. Bad gateway.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77aq0f1hjtkop79wuzkc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F77aq0f1hjtkop79wuzkc.jpg" alt="This is how I felt in that moment."&gt;&lt;/a&gt;&lt;br&gt;
(How I felt in that moment)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I knew if&lt;/strong&gt; I really put my head down, and tried harder, it would work at some point.  But, the thought came to me, I haven't used my free 1 year trial at Amazon Web Services. Why not give it a quick try?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So I created&lt;/strong&gt; an account, set up AWS Amplify, and connected my github repository. Then I changed some things in the DNS records to connect it to the server and voilá. AWS did all the work for me, and automatically set up SSL, continous integration/delivery whenever I pushed to my main repository, and handling all the load balancing and DDoS protection for me. I didn't even have to lift a finger more than a couple times. And now it's up and running. For free. At least for a year...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, question, what should I do with my raspberry pi now?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>aws</category>
      <category>nginx</category>
      <category>react</category>
    </item>
  </channel>
</rss>
