<?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>DEV Community: Hein Thant</title>
    <description>The latest articles on DEV Community by Hein Thant (@indiecodermm).</description>
    <link>https://dev.to/indiecodermm</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%2F1034622%2F8df10bf2-8368-4ab3-bb25-720fb785a4bc.png</url>
      <title>DEV Community: Hein Thant</title>
      <link>https://dev.to/indiecodermm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/indiecodermm"/>
    <language>en</language>
    <item>
      <title>Building A Blog Website with Next.js</title>
      <dc:creator>Hein Thant</dc:creator>
      <pubDate>Tue, 01 Aug 2023 19:42:01 +0000</pubDate>
      <link>https://dev.to/indiecodermm/building-a-blog-website-with-nextjs-5kd</link>
      <guid>https://dev.to/indiecodermm/building-a-blog-website-with-nextjs-5kd</guid>
      <description>&lt;p&gt;I've always wanted a platform that truly reflects my passion for coding and writing. In the past few weeks, I started exploring Next.js and decided to build a personal blog website as a side project. In this article, I want to share my experience and a few things I learned while building this project.&lt;/p&gt;

&lt;p&gt;If you want to see my blog in action, check it out at &lt;a href="https://www.indiecoder.tech/"&gt;www.indiecoder.tech&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple and User-friendly Design
&lt;/h2&gt;

&lt;p&gt;I went for mobile-first approach when designing my blog. I also wanted my website to feel familiar, like scrolling through a social media platform. So, I designed the navbar and homepage to look like a social media app. I also added a dark/light mode feature which is essential in modern web design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Content Management
&lt;/h2&gt;

&lt;p&gt;I chose &lt;a href="https://hygraph.com/"&gt;Hygraph&lt;/a&gt; for managing posts and other content on my website. It offers a GraphQL API and an intuitive UI to easily define schema and organize content. To interact with the API, I used &lt;code&gt;graphql-request&lt;/code&gt; library which provides a convenient way to make GraphQL requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic Routing and SSG
&lt;/h2&gt;

&lt;p&gt;I learned about many powerful features of Next.js while building this app. Dynamic routing and static site generation are especially amazing. With its folder-based routing system, we don't need to set up routers manually like in a React app. For example, when I create &lt;code&gt;about/page.tsx&lt;/code&gt; file inside &lt;code&gt;app/&lt;/code&gt; directory, Next.js renders the page on &lt;code&gt;/about&lt;/code&gt; route.&lt;/p&gt;

&lt;p&gt;To render individual blog posts, I set up a folder like &lt;code&gt;app/posts/[slug]/page.tsx&lt;/code&gt; where &lt;code&gt;[slug]&lt;/code&gt; is a dynamic parameter for each post. Although Next.js can handle most of the dynamic stuff, it doesn't automatically know which routes to generate during the build time. This results in server-side rendering of the page. We can avoid this by defining &lt;code&gt;generateStaticParams&lt;/code&gt; function. Here's the function I used for generating all routes for posts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;generateStaticParams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;getPosts&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Comment System
&lt;/h2&gt;

&lt;p&gt;Every blog needs some social interaction, like comments and reactions. I didn't want to spend a lot of time on creating a reliable comment system. After some research, I found &lt;a href="https://giscus.app/"&gt;Giscus&lt;/a&gt; which uses GitHub Discussions to integrate comments. It's very easy to customize and use. Just adding one component gave me a fully-functional comment system with authentication and reactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Creating my blog website with Next.js has been an amazing experience. Although it's still basic, I feel proud of what I've built and I plan to add more features in the future. &lt;/p&gt;

&lt;p&gt;You can explore the source code on &lt;a href="https://github.com/IndieCoderMM/indiecoder-blog"&gt;GitHub&lt;/a&gt;. I'd love to hear your feedback and suggestions to make it even better.&lt;/p&gt;

&lt;p&gt;Thank you for joining me on this journey, and happy coding! 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Deploying a Rails app on Render</title>
      <dc:creator>Hein Thant</dc:creator>
      <pubDate>Tue, 04 Jul 2023 17:55:57 +0000</pubDate>
      <link>https://dev.to/indiecodermm/deploying-a-rails-app-on-render-o4c</link>
      <guid>https://dev.to/indiecodermm/deploying-a-rails-app-on-render-o4c</guid>
      <description>&lt;p&gt;When it comes to deploying web applications, choosing the right platform can significantly impact development efficiency and overall performance. The Render platform offers a powerful and user-friendly solution for deploying Rails apps. In this tutorial, I'll walk you through a step-by-step guide on how to deploy your Rails + PostgreSQL applications on Render. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Build Script
&lt;/h2&gt;

&lt;p&gt;The first step in preparing your Rails app for deployment is to create a custom build script. This script will allow you to define specific steps required to build your application. To create the script, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;. Open your Rails project's directory.&lt;br&gt;
&lt;strong&gt;Step 2&lt;/strong&gt;. Create a new file named &lt;code&gt;render-build.sh&lt;/code&gt; inside &lt;code&gt;bin&lt;/code&gt; directory.&lt;br&gt;
&lt;strong&gt;Step 3&lt;/strong&gt;. Paste the following script. &lt;em&gt;You can also add the necessary build steps, such as installing node dependencies and compiling assets&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# exit on error&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; errexit

bundle &lt;span class="nb"&gt;install
&lt;/span&gt;bundle &lt;span class="nb"&gt;exec &lt;/span&gt;rake assets:precompile
bundle &lt;span class="nb"&gt;exec &lt;/span&gt;rake assets:clean
bundle &lt;span class="nb"&gt;exec &lt;/span&gt;rake db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;. To ensure &lt;code&gt;bin/render-build.sh&lt;/code&gt; script is executable, run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+x bin/render-build.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring Database and Environment Files
&lt;/h2&gt;

&lt;p&gt;Several configurations need to be updated before deploying your Rails app on Render.&lt;br&gt;
&lt;strong&gt;Step 1&lt;/strong&gt;. Update &lt;code&gt;config/database.yml&lt;/code&gt; with the following changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;production:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DATABASE_URL'] %&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;. Open &lt;code&gt;config/puma.rb&lt;/code&gt; and uncomment the following lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;max_threads_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"RAILS_MAX_THREADS"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;min_threads_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"RAILS_MIN_THREADS"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;max_threads_count&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;threads&lt;/span&gt; &lt;span class="n"&gt;min_threads_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_threads_count&lt;/span&gt;

&lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;environment&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"RAILS_ENV"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"development"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;pidfile&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PIDFILE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"tmp/pids/server.pid"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;workers&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"WEB_CONCURRENCY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;preload_app!&lt;/span&gt;

&lt;span class="n"&gt;plugin&lt;/span&gt; &lt;span class="ss"&gt;:tmp_restart&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;. Enable public file server in &lt;code&gt;config/environments/production.rb&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;public_file_server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'RAILS_SERVE_STATIC_FILES'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'RENDER'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;. Make sure that your project has &lt;code&gt;config/master.key&lt;/code&gt; file. If you don't have a master key yet, delete &lt;code&gt;credentials.yml.enc&lt;/code&gt; and run this command to generate a new one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;EDITOR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"code --wait"&lt;/span&gt; rails credentials:edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up PostgreSQL database
&lt;/h3&gt;

&lt;p&gt;Render simplifies the process of setting up a PostgreSQL database for your Rails app. Follow these steps to get your database up and running:&lt;br&gt;
&lt;strong&gt;Step 1&lt;/strong&gt;. Log in to your Render dashboard.&lt;br&gt;
&lt;strong&gt;Step 2&lt;/strong&gt;. Create a new PostgreSQL database.&lt;br&gt;
&lt;strong&gt;Step 3&lt;/strong&gt;. Provide a name for your database. &lt;br&gt;
&lt;strong&gt;Step 4&lt;/strong&gt;. For &lt;strong&gt;database&lt;/strong&gt; and &lt;strong&gt;username&lt;/strong&gt; values, use the ones specified in &lt;code&gt;config/database.yml&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="ss"&gt;production:
  &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;
  &lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= ENV['DATABASE_URL'] %&amp;gt;
  database: your_database
  username: your_user
  password: &amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"YOUR_APP_DATABASE_PASSWORD"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;. Copy the generated &lt;strong&gt;Internal Database URL&lt;/strong&gt; and &lt;strong&gt;Password&lt;/strong&gt; as you'll need them later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;With your app and database configurations in place, it's time to deploy on Render. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On Render dashboard, click &lt;strong&gt;New&lt;/strong&gt; and choose &lt;strong&gt;Web Service&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Ruby&lt;/strong&gt; as the environment.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Commands&lt;/strong&gt; section, specify the build and start commands.

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Build&lt;/em&gt; : &lt;code&gt;./bin/render-build.sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Start&lt;/em&gt; : &lt;code&gt;bundle exec puma -C config/puma.rb&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Next, add the necessary environment variables:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;DATABASE_URL&lt;/code&gt; : User the &lt;strong&gt;Internal Database URL&lt;/strong&gt; you copied earlier.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;YOUR_APP_DATABASE_PASSWORD&lt;/code&gt;: Use the &lt;strong&gt;Password&lt;/strong&gt; you copied.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RAILS_MASTER_KEY&lt;/code&gt; : Add the key from &lt;code&gt;config/master.key&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Finally, click &lt;strong&gt;Create Web Service&lt;/strong&gt; to deploy your application.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've successfully deployed your Rails app on the Render platform. I hope you found this step-by-step guide helpful in successfully deploying your own application. If you have any further questions or need additional guidance, feel free to reach out to me.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy Coding!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>rails</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
