diff --git a/Dockerfile b/Dockerfile index b0f1dde..9f9281a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,8 @@ ARG APIURL WORKDIR /project ADD . /project/ RUN go mod tidy -RUN GOARCH=wasm GOOS=js go build -o web/app.wasm ./src -RUN go build -o app ./src +RUN GOARCH=wasm GOOS=js go build -o web/app.wasm -ldflags="-X 'main.ApiURL=$APIURL'" ./src +RUN go build -o app -ldflags="-X 'main.ApiURL=$APIURL'" ./src FROM alpine:latest AS staging RUN apk --no-cache add ca-certificates diff --git a/Makefile b/Makefile index b204856..a9ea487 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ -APIURL_prod := https://api.nicecock.eu/api -APIURL_staging := https://api.nicecock.eu/api/testing +APIURL_prod := https://api.quenten.nl/api +APIURL_staging := https://api.quenten.nl/api/testing build: GOARCH=wasm GOOS=js go build -o web/app.wasm -ldflags="-X 'main.ApiURL=${APIURL_staging}'" ./src go build -o app -ldflags="-X 'main.ApiURL=${APIURL_staging}'" ./src +build-new: + GOARCH=wasm GOOS=js go build -o web/app.wasm ./src + go build -o app ./src + build-prod: GOARCH=wasm GOOS=js go build -o web/app.wasm -ldflags="-X 'main.ApiURL=${APIURL_prod}'" ./src go build -o app -ldflags="-X 'main.ApiURL=${APIURL_prod}'" ./src @@ -12,5 +16,8 @@ build-prod: run: build ./app +run-new: build-new + APIURL=${APIURL_staging} ./app + run-prod: build-prod ./app \ No newline at end of file diff --git a/src/homepage.go b/src/homepage.go index b08e0c0..bbba6f7 100644 --- a/src/homepage.go +++ b/src/homepage.go @@ -10,6 +10,10 @@ import ( "github.com/maxence-charriere/go-app/v9/pkg/app" ) +var ( + ApiURL string +) + type Homepage struct { app.Compo } diff --git a/src/main.go b/src/main.go index dce4745..8f0c704 100644 --- a/src/main.go +++ b/src/main.go @@ -4,7 +4,6 @@ import ( "compress/gzip" "log" "net/http" - "os" "github.com/gorilla/handlers" "github.com/maxence-charriere/go-app/v9/pkg/app" @@ -16,10 +15,6 @@ import ( // collection *mongo.Collection //} -var ( - ApiURL string -) - func main() { homepage := NewHomepage() aboutpage := NewAboutPage() @@ -40,11 +35,6 @@ func main() { // It exits immediately on the server side app.RunWhenOnBrowser() - ApiURL = os.Getenv("APIURL") - if ApiURL == "" { - log.Fatalln("Unable to get API URL from environment variables!") - } - icon := &app.Icon{ Default: "/web/static/images/icon-small.png", Large: "/web/static/images/icon.png",