Skip to content

Commit

Permalink
Merge branch 'FEAT/web-dashboard' of https://github.com/bisohns/saido
Browse files Browse the repository at this point in the history
…into FEAT/web-dashboard
  • Loading branch information
Nurudeen38 committed Nov 16, 2022
2 parents 34c9587 + bc49230 commit 72c88e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version=fake
ifeq ($(OS),Windows_NT)
bin=main.exe
build_bin=tmp\main.exe
else
bin=main
build_bin=tmp/main
endif
# Example:
# make
Expand Down Expand Up @@ -53,6 +55,6 @@ build-frontend:

.PHONY: serve-backend
serve-backend:
air --build.cmd "go build -o ./tmp/$(bin) ." --build.bin "tmp/$(bin)" --build.exclude_dir "assets,docs,tmp,web,scripts,ssh-key,.github,.git" --build.include_ext "go,yaml,html,js" --build.exclude_file "config.example.yaml" --build.args_bin "dashboard,--config,config-test.yaml" --build.stop_on_error true --misc.clean_on_exit true --log.time true
air --build.cmd "go build -o ./tmp/$(bin) ." --build.bin "$(build_bin)" --build.exclude_dir "assets,docs,tmp,web,scripts,ssh-key,.github,.git" --build.include_ext "go,yaml,html,js" --build.exclude_file "config.example.yaml" --build.args_bin "dashboard,--config,config-test.yaml" --build.stop_on_error true --misc.clean_on_exit true --log.time true

app: build-frontend serve-backend
9 changes: 8 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"net/http"
"os"
"path"
"runtime"
"strconv"
"strings"

"github.com/bisohns/saido/client"
"github.com/bisohns/saido/config"
Expand Down Expand Up @@ -50,13 +52,18 @@ func (f fsFunc) Open(name string) (fs.File, error) {

func EmbedHandler(prefix, root string) http.Handler {
handler := fsFunc(func(name string) (fs.File, error) {
defaultPath := fmt.Sprintf("%s/index.html", root)
assetPath := path.Join(root, name)
if runtime.GOOS == "windows" {
defaultPath = strings.ReplaceAll(defaultPath, `/`, `\`)
assetPath = strings.ReplaceAll(assetPath, `/`, `\`)
}

// If we can't find the asset, return the default index.html
// build
f, err := build.Open(assetPath)
if os.IsNotExist(err) {
return build.Open(fmt.Sprintf("%s/index.html", root))
return build.Open(defaultPath)
}

// Otherwise assume this is a legitimate request routed
Expand Down

0 comments on commit 72c88e8

Please sign in to comment.