What is Nostr?
Egge /
npub1mhc…c226
2024-06-12 14:59:37

Egge on Nostr: I finally made it. npubcash-server is now deployable without much hassle. 🥜 This ...

I finally made it. npubcash-server is now deployable without much hassle. 🥜

This is not final and merged yet, so please proceed with caution. If you try it out, please let me know when you break something 💜🙌🏻
_Disclaimer: Beware, there be dragons... Deploying your own version of npubcash-server is highly experimental. Do not use this in production yet. If you do deploy it, please make sure to leave your feedback with [me](https://njump.me/npub1mhcr4j594hsrnen594d7700n2t03n8gdx83zhxzculk6sh9nhwlq7uc226)._

## Prerequisites

Before we dive in, you'll need a few things:

1. **Blink API Key**: npubcash-server uses Blink API for payment callbacks. If you don’t have a Blink account yet, sign up [here](https://dashboard.blink.sv/).
2. **Postgres**: npubcash-server utilizes a Postgres database for storage.
3. **fly.io Account and flyctl**: While you can deploy npubcash-server anywhere, this guide focuses on fly.io and its CLI tool, flyctl.

## Setup

### Step 1: Clone the Repository

First, clone the npubcash-server repository, specifically the `migrations` branch, as it contains the necessary deployment scripts. Don’t forget to clone all submodules recursively.

```zsh
git clone -b migrations --recurse-submodules https://github.com/cashubtc/npubcash-server.git
cd npubcash-server
```

### Step 2: Create fly.toml Configuration

Next, create your `fly.toml` file to configure your deployment.

```zsh
nvim fly.toml
```

Here's a sample configuration. Adjust the environment variables to match your setup:

```toml
app = "npubcash-server"
primary_region = "ams"

[build]

[http_service]
internal_port = 8000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[vm]]
memory = "512mb"
cpu_kind = "shared"
cpus = 1

[env]
NODE_ENV = "production"
PGUSER = ""
PGPASSWORD = ""
PGHOST = ""
PGDATABASE = ""
PGPORT = ""
MINTURL = ""
BLINK_API_KEY = ""
BLINK_WALLET_ID = ""
BLINK_URL = "https://api.blink.sv/graphql"
HOSTNAME = ""
JWT_SECRET = ""
ZAP_SECRET_KEY = ""
LNURL_MIN_AMOUNT = ""
LNURL_MAX_AMOUNT = ""
NPC_SERVER_URL = ""
```

**Note:** fly.io offers additional security for sensitive environment variables through `secrets`, which are encrypted and never exposed directly. Consider using `secrets` for sensitive data like your Blink or Nostr key. Learn more [here](https://fly.io/docs/reference/secrets/#setting-secrets).

## Deploying

With your configuration ready, it’s time to deploy!

```zsh
fly launch
```

When prompted, choose to use the existing `fly.toml` file by inputting `y`. Fly.io might suggest deploying a Postgres instance, but since we're using an external Postgres instance, adjust the settings as needed through their web interface. Watch the build logs in your terminal, and once completed, your instance of npubcash-server is live. Congrats!
## Setting Up a Custom Domain

To fully utilize npubcash-server as an LNURL server, you’ll need a custom domain. Here’s how to set it up:

1. **Get the IP Address**: Use flyctl to list your IP addresses.

```zsh
fly ips list
```

Copy the IPv4 and IPv6 addresses.

2. **Create DNS Records**: Set up an A record with your domain provider using the IPv4 address and a AAAA record using the IPv6 address.

3. **Request an SSL Certificate**: For encrypted traffic, request a Let’s Encrypt certificate.

```zsh
fly certs add
```

**Note:** DNS propagation can take some time. Ensure your machine is running and try connecting to the domain once the DNS records are updated. Fly.io will verify the DNS setup when traffic starts coming in.

## Wrapping up

That is it... Hopefully by now your very own instance of npubcash-server is running and reachable on your own domain. If you got this far, please reach out to me and let me know.
Now please go ahead and try to break it. If you do, please open an [issue](https://github.com/cashubtc/npubcash-server/issues/new/choose) so that I can fix it :)
Author Public Key
npub1mhcr4j594hsrnen594d7700n2t03n8gdx83zhxzculk6sh9nhwlq7uc226