How to Deploy Next.js App to AWS EC2 in Production and Set up CI/CD with Github Actions

Yo!

In this article, we’ll be discussing how to deploy a Next.js app to AWS EC2 and set up continuous integration and deployment using Github Actions.

Before proceeding, you will need to have the infrastructure ready on AWS, which can be deployed manually or by using Terraform code. I’ll be skipping the infrastructure setup part for the purpose of this article.

First things first, we need to SSH into the EC2 instance. Once you’re logged in, run this script to install Node.js on the machine:

How to Configure Vim as Your Go IDE

Vim/Neovim is my IDE for day-to-day work. My vimrc file can be found here.

This article is all about Vim(not Neovim), and I assume that you have already configured Vim as your code editor.

Okay, let’s get started by installing fatih/vim-go plugin with your favorite vim plugin manager.

After that, if you have Go installed correctly on your machine already, you will be able to run :GoInstallBinaries.

Next, install coc.nvim plugin, which is a great language server host for Vim.

How to Setup Eslint and Prettier With Git Precommit Hooks in React Typescript Project

You may create a new react app with typescript like so:

1
npx create-react-app my-app --template typescript

Now let’s setup eslint and prettier.

Remove eslintConfig from package.json.

Install prettier using these commands:

1
2
3
yarn add --dev --exact prettier
# these are for making eslint and prettier to play well together
yarn add --dev eslint-config-prettier eslint-plugin-prettier

Create config files like this:

Improve Your Wireguard Server's Performance

The default MTU(Maximum Transmission Unit) is 1420 in wireguard, while the most other devices use 1496 or 1500.

Read here for more info.

TL;DR

Stop the wireguard interface in use:

sudo systemctl stop wg-quick@wg0
# or
sudo wg-quick down wg0

Edit the wireguard config file:

sudo vim /etc/wireguard/wg0.conf

Add MTU=1400 to the Interface section like this:

1
2
3
4
5
6
[Interface]
Address = 10.10.10.1/24
SaveConfig = true
ListenPort = 51820
MTU = 1400
PrivateKey = xxxxxx

And start the stopped service:

Redux Setup in Your React Project - Personal Preference

The first thing is to install libraries for redux, as you may guess:

1
npm install -S redux react-redux redux-logger reselect redux-persist

redux-logger is a redux middleware which is really really helpful in development, but it’s up to you whether to use it or not. reselect is a memoization implementation for redux. redux-persist is for leveraging localStorage/sessionStorage browser APIs in redux.

Assuming that you have the react project structured in your own way, I’d create a new folder named redux inside the src/app folder: