mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 10:47:19 +03:00
Use bindata to embed UI assets
This commit is contained in:
parent
ed31b6fa31
commit
50d89760e2
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,3 +11,5 @@ sonic.toml
|
|||||||
master.zip
|
master.zip
|
||||||
Jamstash-master
|
Jamstash-master
|
||||||
testDB
|
testDB
|
||||||
|
*.swp
|
||||||
|
*_gen.go
|
||||||
|
28
Makefile
28
Makefile
@ -26,17 +26,14 @@ testall: check_go_env test
|
|||||||
build: check_go_env
|
build: check_go_env
|
||||||
go build
|
go build
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
buildall: check_go_env build
|
|
||||||
@(cd ./ui && npm run build)
|
|
||||||
|
|
||||||
.PHONY: setup
|
.PHONY: setup
|
||||||
setup: Jamstash-master
|
setup: Jamstash-master
|
||||||
@which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex)
|
@which reflex || (echo "Installing Reflex" && GO111MODULE=off go get -u github.com/cespare/reflex)
|
||||||
@which goconvey || (echo "Installing GoConvey" && GO111MODULE=off go get -u github.com/smartystreets/goconvey)
|
@which goconvey || (echo "Installing GoConvey" && GO111MODULE=off go get -u github.com/smartystreets/goconvey)
|
||||||
@which wire || (echo "Installing Wire" && GO111MODULE=off go get -u go get github.com/google/wire/cmd/wire)
|
@which wire || (echo "Installing Wire" && GO111MODULE=off go get -u go get github.com/google/wire/cmd/wire)
|
||||||
@which goreman || (echo "Installing Goreman" && GO111MODULE=off go get -u github.com/mattn/goreman)
|
@which goreman || (echo "Installing Goreman" && GO111MODULE=off go get -u github.com/mattn/goreman)
|
||||||
@which ginkgo || (echo "Installing Ginkgo" && GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo)
|
@which ginkgo || (echo "Installing Ginkgo" && GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo)
|
||||||
|
@which go-bindata || (echo "Installing BinData" && GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...)
|
||||||
go mod download
|
go mod download
|
||||||
@(cd ./ui && npm ci)
|
@(cd ./ui && npm ci)
|
||||||
|
|
||||||
@ -60,3 +57,16 @@ check_node_env:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
mkdir data
|
mkdir data
|
||||||
|
|
||||||
|
UI_SRC = $(shell find ui/src -name "*.js")
|
||||||
|
UI_PUBLIC = $(shell find ui/public -name "*.js")
|
||||||
|
ui/build: $(UI_SRC) $(UI_PUBLIC)
|
||||||
|
@(cd ./ui && npm run build)
|
||||||
|
|
||||||
|
assets/gen.go: ui/build
|
||||||
|
go-bindata -fs -prefix "ui/build" -tags embed -nocompress -pkg assets -o assets/gen.go ui/build/...
|
||||||
|
|
||||||
|
.PHONY: buildall
|
||||||
|
buildall: check_go_env assets/gen.go
|
||||||
|
go build -tags embed
|
||||||
|
|
||||||
|
13
assets/external.go
Normal file
13
assets/external.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// +build !embed
|
||||||
|
|
||||||
|
package assets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/cloudsonic/sonic-server/consts"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AssetFile() http.FileSystem {
|
||||||
|
return http.Dir(consts.UIAssetsLocalPath)
|
||||||
|
}
|
@ -11,4 +11,6 @@ const (
|
|||||||
|
|
||||||
InitialUserName = "admin"
|
InitialUserName = "admin"
|
||||||
InitialName = "Admin"
|
InitialName = "Admin"
|
||||||
|
|
||||||
|
UIAssetsLocalPath = "ui/build"
|
||||||
)
|
)
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cloudsonic/sonic-server/assets"
|
||||||
"github.com/cloudsonic/sonic-server/conf"
|
"github.com/cloudsonic/sonic-server/conf"
|
||||||
"github.com/cloudsonic/sonic-server/model"
|
"github.com/cloudsonic/sonic-server/model"
|
||||||
"github.com/cloudsonic/sonic-server/server"
|
|
||||||
"github.com/deluan/rest"
|
"github.com/deluan/rest"
|
||||||
"github.com/go-chi/chi"
|
"github.com/go-chi/chi"
|
||||||
"github.com/go-chi/jwtauth"
|
"github.com/go-chi/jwtauth"
|
||||||
@ -39,9 +39,6 @@ func (app *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (app *Router) routes() http.Handler {
|
func (app *Router) routes() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
// Serve UI app assets
|
|
||||||
server.FileServer(r, app.path, "/", http.Dir("ui/build"))
|
|
||||||
|
|
||||||
// Basic unauthenticated ping
|
// Basic unauthenticated ping
|
||||||
r.Get("/ping", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"response":"pong"}`)) })
|
r.Get("/ping", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"response":"pong"}`)) })
|
||||||
|
|
||||||
@ -57,6 +54,10 @@ func (app *Router) routes() http.Handler {
|
|||||||
app.R(r, "/album", model.Album{})
|
app.R(r, "/album", model.Album{})
|
||||||
app.R(r, "/artist", model.Artist{})
|
app.R(r, "/artist", model.Artist{})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Serve UI app assets
|
||||||
|
r.Handle("/*", http.StripPrefix(app.path, http.FileServer(assets.AssetFile())))
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user