From 7faf94fa6d94e7c07fea70fe1e3fd39db707f27c Mon Sep 17 00:00:00 2001 From: Ryan Hamamura <58859899+ryanhamamura@users.noreply.github.com> Date: Wed, 4 Feb 2026 07:02:52 -1000 Subject: [PATCH] feat: make invite link base URL configurable via APP_URL Load environment variables from .env file using godotenv. Defaults to https://demo.adriatica.io if APP_URL is not set. --- .env.example | 5 +++++ .gitignore | 1 + go.mod | 3 ++- go.sum | 2 ++ main.go | 3 +++ ui/snakestatus.go | 2 +- ui/status.go | 11 +++++++++-- 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..af41a04 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +# Application URL for invite links (defaults to https://demo.adriatica.io) +# APP_URL=http://localhost:7331 + +# Server port (defaults to 7331) +# PORT=7331 diff --git a/.gitignore b/.gitignore index 0b4d69a..58dd18e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ c4 c4.db data/ +.env # Deploy artifacts c4-deploy-*.tar.gz diff --git a/go.mod b/go.mod index 78aacae..c6b36f3 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.25.4 require ( github.com/google/uuid v1.6.0 + github.com/joho/godotenv v1.5.1 github.com/pressly/goose/v3 v3.26.0 github.com/ryanhamamura/via v0.4.0 golang.org/x/crypto v0.47.0 - maragu.dev/gomponents v1.2.0 modernc.org/sqlite v1.44.0 ) @@ -43,6 +43,7 @@ require ( golang.org/x/sync v0.18.0 // indirect golang.org/x/sys v0.40.0 // indirect golang.org/x/time v0.14.0 // indirect + maragu.dev/gomponents v1.2.0 // indirect modernc.org/libc v1.67.4 // indirect modernc.org/mathutil v1.7.1 // indirect modernc.org/memory v1.11.0 // indirect diff --git a/go.sum b/go.sum index 6884081..6fad861 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hookenz/gotailwind/v4 v4.1.18 h1:1h3XwTVx1dEBm6A0bcosAplNCde+DCmVJG0arLy5fBE= github.com/hookenz/gotailwind/v4 v4.1.18/go.mod h1:IfiJtdp8ExV9HV2XUiVjRBvB3QewVXVKWoAGEcpjfNE= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk= github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4= diff --git a/main.go b/main.go index 480ad7d..7f6d6aa 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "os" "github.com/google/uuid" + "github.com/joho/godotenv" "github.com/ryanhamamura/c4/auth" "github.com/ryanhamamura/c4/db" @@ -46,6 +47,8 @@ func port() string { } func main() { + _ = godotenv.Load() + if err := db.Init("c4.db"); err != nil { log.Fatal(err) } diff --git a/ui/snakestatus.go b/ui/snakestatus.go index d323fc1..7998aa7 100644 --- a/ui/snakestatus.go +++ b/ui/snakestatus.go @@ -130,7 +130,7 @@ func SnakePlayerList(sg *snake.SnakeGame, mySlot int) h.H { } func SnakeInviteLink(gameID string) h.H { - fullURL := baseURL + "/snake/" + gameID + fullURL := getBaseURL() + "/snake/" + gameID return h.Div(h.Class("mt-4 text-center"), h.P(h.Text("Share this link to invite players:")), h.Div(h.Class("bg-base-200 p-4 rounded-lg font-mono break-all my-2"), diff --git a/ui/status.go b/ui/status.go index a606120..58e5af0 100644 --- a/ui/status.go +++ b/ui/status.go @@ -1,6 +1,8 @@ package ui import ( + "os" + "github.com/ryanhamamura/c4/game" "github.com/ryanhamamura/via/h" ) @@ -115,10 +117,15 @@ func PlayerInfo(g *game.Game, myColor int) h.H { ) } -const baseURL = "https://demo.adriatica.io" +func getBaseURL() string { + if url := os.Getenv("APP_URL"); url != "" { + return url + } + return "https://demo.adriatica.io" +} func InviteLink(gameID string) h.H { - fullURL := baseURL + "/game/" + gameID + fullURL := getBaseURL() + "/game/" + gameID return h.Div(h.Class("mt-4 text-center"), h.P(h.Text("Share this link with your opponent:")), h.Div(h.Class("bg-base-200 p-4 rounded-lg font-mono break-all my-2"),