diff --git a/Makefile b/Makefile index a4df78f7..26e40b80 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ export PATH := $(PATH):`go env GOPATH`/bin export GO111MODULE=on LDFLAGS := -s -w +NOWEB_TAG = $(shell [ ! -d web/frps/dist ] || [ ! -d web/frpc/dist ] && echo ',noweb') .PHONY: web frps-web frpc-web frps frpc @@ -28,23 +29,23 @@ fmt-more: gci: gci write -s standard -s default -s "prefix(github.com/fatedier/frp/)" ./ -vet: web - go vet ./... +vet: + go vet -tags "$(NOWEB_TAG)" ./... frps: - env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -tags frps -o bin/frps ./cmd/frps + env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -tags "frps$(NOWEB_TAG)" -o bin/frps ./cmd/frps frpc: - env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -tags frpc -o bin/frpc ./cmd/frpc + env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -tags "frpc$(NOWEB_TAG)" -o bin/frpc ./cmd/frpc test: gotest -gotest: web - go test -v --cover ./assets/... - go test -v --cover ./cmd/... - go test -v --cover ./client/... - go test -v --cover ./server/... - go test -v --cover ./pkg/... +gotest: + go test -tags "$(NOWEB_TAG)" -v --cover ./assets/... + go test -tags "$(NOWEB_TAG)" -v --cover ./cmd/... + go test -tags "$(NOWEB_TAG)" -v --cover ./client/... + go test -tags "$(NOWEB_TAG)" -v --cover ./server/... + go test -tags "$(NOWEB_TAG)" -v --cover ./pkg/... e2e: ./hack/run-e2e.sh diff --git a/Release.md b/Release.md index 5aaf921f..c4425976 100644 --- a/Release.md +++ b/Release.md @@ -5,3 +5,4 @@ ## Improvements * Kept proxy/visitor names as raw config names during completion; moved user-prefix handling to explicit wire-level naming logic. +* Added `noweb` build tag to allow compiling without frontend assets. `make build` now auto-detects missing `web/*/dist` directories and skips embedding, so a fresh clone can build without running `make web` first. The dashboard gracefully returns 404 when assets are not embedded. diff --git a/assets/assets.go b/assets/assets.go index 2d7a164e..713087ad 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -29,14 +29,23 @@ var ( prefixPath string ) +type emptyFS struct{} + +func (emptyFS) Open(name string) (http.File, error) { + return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist} +} + // if path is empty, load assets in memory // or set FileSystem using disk files func Load(path string) { prefixPath = path - if prefixPath != "" { + switch { + case prefixPath != "": FileSystem = http.Dir(prefixPath) - } else { + case content != nil: FileSystem = http.FS(content) + default: + FileSystem = emptyFS{} } } diff --git a/pkg/util/version/version.go b/pkg/util/version/version.go index 4a601f32..c98b7cfb 100644 --- a/pkg/util/version/version.go +++ b/pkg/util/version/version.go @@ -14,7 +14,7 @@ package version -var version = "0.67.0" +var version = "0.68.0" func Full() string { return version diff --git a/web/frpc/embed.go b/web/frpc/embed.go index ce06ff90..77b4863e 100644 --- a/web/frpc/embed.go +++ b/web/frpc/embed.go @@ -1,3 +1,5 @@ +//go:build !noweb + package frpc import ( diff --git a/web/frpc/embed_stub.go b/web/frpc/embed_stub.go new file mode 100644 index 00000000..591a770a --- /dev/null +++ b/web/frpc/embed_stub.go @@ -0,0 +1,3 @@ +//go:build noweb + +package frpc diff --git a/web/frps/embed.go b/web/frps/embed.go index 6bdc475f..a1264d7c 100644 --- a/web/frps/embed.go +++ b/web/frps/embed.go @@ -1,3 +1,5 @@ +//go:build !noweb + package frps import ( diff --git a/web/frps/embed_stub.go b/web/frps/embed_stub.go new file mode 100644 index 00000000..35c9d9c8 --- /dev/null +++ b/web/frps/embed_stub.go @@ -0,0 +1,3 @@ +//go:build noweb + +package frps