From ef4d5c3bb939f46b0ed20f8a8a2cd5f3362ddb93 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Thu, 7 Mar 2024 23:46:59 +0200 Subject: [PATCH] Fix routing to get rid of the awkward symlink dereferencing on build --- README.md | 4 ---- build.sh | 13 +------------ main.go | 4 +++- static/html/coils/index.html | 1 - static/html/registers/index.html | 1 - 5 files changed, 4 insertions(+), 19 deletions(-) delete mode 120000 static/html/coils/index.html delete mode 120000 static/html/registers/index.html diff --git a/README.md b/README.md index 165efc0..7c0a7cb 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,6 @@ has been used. ### Building - clone or download the repo -- `static/html/index.html` is symlinked to `coils` and `registers` - for development purposes, the symlinks need to be dereferenced before - building the binary on filesystems that support symlinks - - Replace symlinks with copies of the files or use e.g. `tar -h` - Build for the correct architecture, e.g. for Linux 32-bit ARM (Rpi Zero W 1): ``` cd /path/to/repo diff --git a/build.sh b/build.sh index 804260c..ef434bf 100755 --- a/build.sh +++ b/build.sh @@ -12,15 +12,4 @@ ARCH=${1:-"amd64"} VERSION=$(grep -e 'version.*=' main.go | awk '{print $3}' | tr -d '"') -[[ ! -d "TMP" ]] && mkdir -p TMP - -pushd TMP &> /dev/null || exit 1 - -tar --exclude ../TMP -ch ../* | tar xf - - -#env GOOS=linux GOARCH=arm go build -o ../BUILD/enervent-ctrl-${VERSION}.linux-arm32 . -CGO_ENABLED=0 GOOS=linux GOARCH="$ARCH" go build -o "../BUILD/enervent-ctrl-${VERSION}.linux-$ARCH" . - -rm -rf ./* - -popd &> /dev/null || exit 1 +CGO_ENABLED=0 GOOS=linux GOARCH="$ARCH" go build -o "../BUILD/enervent-ctrl-${VERSION}.linux-$ARCH" . \ No newline at end of file diff --git a/main.go b/main.go index 527374f..962e8bc 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( var static embed.FS var ( - version = "0.1.1" + version = "0.1.2" device pingvin.Pingvin config Conf usernamehash [32]byte @@ -64,6 +64,8 @@ func serve(cert, key *string) { } htmlroot := http.FileServer(http.FS(html)) http.HandleFunc("/", authHandler(htmlroot)) + http.HandleFunc("/coils/", authHandler(http.StripPrefix("/coils/", htmlroot))) + http.HandleFunc("/registers/", authHandler(http.StripPrefix("/registers/", htmlroot))) logdst, err := os.OpenFile(os.DevNull, os.O_WRONLY, os.ModeAppend) if err != nil { log.Fatal(err) diff --git a/static/html/coils/index.html b/static/html/coils/index.html deleted file mode 120000 index 79c5d6f..0000000 --- a/static/html/coils/index.html +++ /dev/null @@ -1 +0,0 @@ -../index.html \ No newline at end of file diff --git a/static/html/registers/index.html b/static/html/registers/index.html deleted file mode 120000 index 79c5d6f..0000000 --- a/static/html/registers/index.html +++ /dev/null @@ -1 +0,0 @@ -../index.html \ No newline at end of file