HTTP is Dead!
The thing about Rails that I like is that it comes with a lot of defaults and ready-made Ruby gems. As one of the main doctrines is convention over configuration. My oldest toy project has been serving the front end and back end as one single monolith application since 2015. Though the domain has evolved since then, it always comes with an SSL certificate. It’s 2023, and HTTP is dead!
API-only Rails
We will rarely see a monolith app nowadays. Most of them are single-page application client app that communicates through REST endpoints. It decouples the front end and the back end part, speeds up the development, and isolates the failure.
Creating a new Rails API-only app is not an option for me. A, being the codebase is complex. B, I already have another toy project with API-only Rails. So, decoupling an old Rails 6 monolith app to an API-only Rails app sounds like a fun project for me.
Certbot x Nginx
Turns out, it is not that hard. The key is to generate the certificates with the existing domains as the parameters. So, I already set up the naked domain (musik88.com) and its www (www.musik88.com). All I have to do is to run this command with sudo:
$ sudo certbot certonly --cert-name musik88.com -d musik88.com,www.musik88.com,api.musik88.com
And my SSL for api.musik88.com is ready.
It goes without saying that I need to add the new API subdomain to the existing nginx configuration. In the server_name block, precisely.
server_name www.musik88.com musik88.com api.musik88.com;