Setup environment files
Configuration of the .env file
The .env
file contains various environment variables that need to be properly
configured for the application to work correctly. Below, I will explain how to
obtain the values for some of these variables.
Setting up Resend for sending emails
The “RESEND for email” section in the .env
file contains the “RESEND_API_KEY”
variable, which corresponds to the Resend API key that you need to set up to
send emails.
Here’s how to obtain the Resend API key:
-
Access the Resend website at https://resend.com and log in with your account or create a new account if you don’t have one.
-
Once you’ve logged in, look for the option to add a new API Key. You can do this by clicking the corresponding button or navigating to the “API Keys” section and creating it from there.
-
Fill in the necessary information to create the API Key, such as the name and required permissions.
-
Once the API Key is created, copy its value, which usually starts with “re_” and includes a series of characters.
-
Paste this API Key value into the
.env
file under the “RESEND_API_KEY” variable. It should look something like this (real values without censorship):
Replace the key with the actual Resend API key you obtained from your Resend account.
Setting up Upstash (QStash and Redis)
The “Upstash for queue” section in the .env
file contains the following
variables related to QStash and Redis:
To configure UPSTASH correctly, follow these steps:
Obtaining QStash Keys
-
Log in to your UPSTASH account at https://upstash.com/ or create a new account if you don’t have one yet.
-
Once logged in, go to https://console.upstash.com/qstash and copy the keys you need one by one. These keys are “QSTASH_CURRENT_SIGNING_KEY”, “QSTASH_NEXT_SIGNING_KEY”, and “QSTASH_TOKEN”.
-
Paste these keys into the
.env
file under their respective variables. It should look something like this (real values without censorship):
Replace the ellipsis with the actual keys you obtained from UPSTASH.
Configuring Redis
We have been using Redis for the waiting list in this project. It is not used currently. However, if you want to use it, you can follow the steps below to.
-
Create a Redis database in UPSTASH through https://console.upstash.com/.
-
Once the database is created, access “Details” and go to the “API REST” section, selecting the
.env
tab. -
Copy the URL and token information displayed there and paste them in the
.env
file under the following variables:
Replace the ellipsis with the actual URL and token of Redis you obtained from UPSTASH.
Setting up Tinybird
You will need to create an API token, Go to Auth tokens > Workspace tokens > Add a new token > Select your token
The Tinybird CLI can be used to push the pipes to the Tinybird server.
Datasource
We ingest the monitor response into the ping_response__v5
table. If you want
to have some dummy data to start with, check out the
csv
file.
Warning: If importing the csv file, make sure to change the column names are identical (e.g.
monitorId
instead ofmonitorid
). Otherwise, the pipes will not work.
Pipes
The pipes we are using can be found under @packages/tinybird/pipes
. Pipes are
used to transform data from one format to another. For example, we are using a
pipe to transform the data from the database ping_response
into aggregated
data.
We currently have three pipes:
status_timezone__v0
: returns aggregated data from theping_response
table.response_list__v0
: returns the list of responses from theping_response
table.home_stats__v0
: returns the total amount of pings during a timeframe from theping_response
table.
Setting up Turso (SQLite or Cloud Database)
The “TURSO SQLITE” section in the .env
file allows you to configure Turso
database, either a local SQLite database or a cloud-based database.
If you want to use a local database (optional):
To begin, install sqld with brew. If you don’t have brew installed, we recommend installing it from brew.sh which works on macOS or Linux, or WSL if you are using Windows.
Next, you can use the following command to start Turso with a SQLite database:
By doing this, you’ll be able to work with the local database without modifying
the .env
file.
If you want to use a cloud-based database with Turso
To use a cloud-based database with Turso, follow these steps:
-
Log in to your Turso account at https://turso.tech/ or create a new account if you don’t have one yet.
-
If this is your first time using Turso, it may prompt you to install the client on your machine. Follow the steps provided on their website or refer to their documentation https://docs.turso.tech/tutorials/get-started-turso-cli/step-01-installation for client installation.
-
Once you have successfully installed the Turso client, open your terminal and use the following command to authenticate:
- Then, create a new database with the following command:
Wait for a moment until the database is created, and you will be shown information about the database, including a connection URL and an authentication token.
- Use the following commands to show the required information and create the
database in the
.env
file:
Replace “db-name” with the name of your database. You should get the generated
URL and token, which should be placed in the .env
file as follows (real values
without censorship):
Remember to copy this information in both app/web/.env
and packages/db/.env
and save the changes to the .env
file once you have completed all the
configurations.
Connect datasource using tinybird-cli
-
Log in to your tinybird account at https://www.tinybird.co/ or create a new account if you don’t have one yet.
-
Once logged in, go to your dashboard and copy the auth token and paste inside
.env
Please make sure you chose the admin token otherwise it may give an error like auth token invalid
-
Then download this file ping_response__v5
-
install the tinybird-cli
-
Create a datasource from this file
Please make sure while importing you edit the table header fields in camelcase .
-
Create pipe from the datasource name as a
response_list__v1
andstatus_timezone__v0
-
Inside
response_list__v0
pipe, create a endpoint by running a following query :
- Inside
status_timezone__v0
pipe , create a endpoint by running a following query :
Setting up the database
We have an example database that you can use to get started. You can run it with the following command:
It contains some dummy data that you can use to test the application.
Conclusion
Once you have collected all the necessary information, you should save it in the
.env
file to ensure proper configuration for your application. Following these
steps will enable your application to function effectively with the appropriate
settings for each service.
Open this url http://localhost:3000/app/love-openstatus to start using the app.