From 029b426757d943bb4a6db9795012920b297a156a Mon Sep 17 00:00:00 2001 From: DutchEllie Date: Fri, 27 May 2022 20:35:53 +0200 Subject: [PATCH] Made generating static site possible --- Makefile | 3 +++ src/main.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/Makefile b/Makefile index a9ea487..0ed0a90 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,17 @@ 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 + cp -r web staticsite/ build-new: GOARCH=wasm GOOS=js go build -o web/app.wasm ./src go build -o app ./src + cp -r web staticsite/ 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 + cp -r web staticsite/ run: build ./app diff --git a/src/main.go b/src/main.go index b2c6250..01bfbd5 100644 --- a/src/main.go +++ b/src/main.go @@ -4,6 +4,7 @@ import ( "compress/gzip" "log" "net/http" + "os" "github.com/gorilla/handlers" "github.com/maxence-charriere/go-app/v9/pkg/app" @@ -89,6 +90,9 @@ func main() { app.GenerateStaticWebsite("./staticsite", handler) compressed := handlers.CompressHandlerLevel(handler, gzip.BestSpeed) http.Handle("/", compressed) + if os.Getenv("GEN_STATIC_SITE") == "true" { + return + } if err := http.ListenAndServe(":8000", nil); err != nil { log.Fatal(err)