This service will provide APIs for the frontend to do following things:
Create and manage bank accounts, which are composed of owner’s name, balance, and currency.
Record all balance changes to each of the account. So every time some money is added to or subtracted from the account, an account entry record will be created.
Perform a money transfer between 2 accounts. This should happen within a transaction, so that either both accounts’ balance are updated successfully or none of them are.
Check out the getting started guide here for installing the Fly CLI. Once you have the CLI installed, you can deploy the app with the following command:
Clone the repo:
git clone https://github.com/umarhadi/bank-server.git && cd bank-server
Create postgres database:
flyctl postgres create
After that, you will get the database url, save it for later.
Set environment variable
DB_SOURCE
flyctl secrets set DB_SOURCE="postgres://postgres:db_password@db_host:5432/postgres?sslmode=disable"
Replace db_password and db_host with the actual password and host from the database url. Don't delete sslmode=disable part, if you delete it, the app will not be able to connect to the database because connection between the app and the database is not encrypted via fly.io internal network.
TOKEN_SYMMETRIC_KEY
flyctl secrets set TOKEN_SYMMETRIC_KEY="your_token_symmetric_key"
Replace your_token_symmetric_key with your own 32 symmetric key. You can generate it with this tool or
openssl rand -hex 64 | head -c 32
Another environment variable
You can change the default value of the environment variable in the fly.toml file.