Skip to content

Commit

Permalink
auto create users.json if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
github-tijlxyz committed Feb 28, 2024
1 parent 7e6a3f0 commit 88b6fa0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ A relay based on [Khatru](https://github.com/fiatjaf/khatru) with a invite hiera

### Deploy with docker

1. create and manually add a pubkey to users.json: `touch users.json && echo '{"your nostr hex pubkey":""}' > users.json`
2. deploy with docker: `docker run -p 3334:3334 -v ./users.json:/app/users.json -v ./db:/app/db -e DOMAIN=yourdomain.example.com -e RELAY_NAME="your relay name" -e RELAY_PUBKEY="your nostr hex pubkey" tijlxyz/khatru-pyramid:latest`
```
docker run \
-p 3334:3334 \
-v ./users.json:/app/users.json \
-v ./db:/app/db \
-e DOMAIN=yourdomain.example.com \
-e RELAY_NAME="your relay name" \
-e RELAY_PUBKEY="your nostr hex pubkey" \
tijlxyz/khatru-pyramid:latest
```

1 change: 0 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Server Settings
DOMAIN="example.com"
PORT="3334" # optional
Expand Down
16 changes: 15 additions & 1 deletion whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -89,7 +90,20 @@ func removeDescendantsFromWhitelist(ancestor string) {
func loadWhitelist() error {
b, err := os.ReadFile(s.UserdataPath)
if err != nil {
return err
// If the whitelist file does not exist, with RELAY_PUBKEY
if errors.Is(err, os.ErrNotExist) {
whitelist[s.RelayPubkey] = ""
jsonBytes, err := json.Marshal(&whitelist)
if err != nil {
return err
}
if err := os.WriteFile(s.UserdataPath, jsonBytes, 0644); err != nil {
return err
}
return nil
} else {
return err
}
}

if err := json.Unmarshal(b, &whitelist); err != nil {
Expand Down

0 comments on commit 88b6fa0

Please sign in to comment.